怎么在servlet里面获取spring通过注解方式注入的service bean?

2024-11-28 19:37:27
推荐回答(1个)
回答1:

private static ApplicationContext applicationContext;/*** 实现ApplicationContextAware接口的回调方法,设置上下文环境*/public void setApplicationContext(ApplicationContext applicationContext){
SpringContextUtil.applicationContext = applicationContext;}
public static ApplicationContext getApplicationContext(){
return applicationContext;}/*** 获取对象*@returnObject 一个以所给名字注册的bean的实例 (service注解方式,自动生成以首字母小写的类名为bean name)*/public static Object getBean(String name) throws BeansException{