怎么在servlet里面获取spring通过注解方式注入的service bean?
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{
SpringContextUtil.applicationContext = applicationContext;}
public static ApplicationContext getApplicationContext(){
return applicationContext;}/*** 获取对象*@returnObject 一个以所给名字注册的bean的实例 (service注解方式,自动生成以首字母小写的类名为bean name)*/public static Object getBean(String name) throws BeansException{
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询