zoukankan      html  css  js  c++  java
  • ServletContextListener中@Autowired失效的解决方法

    @WebListener
    public class ContextWebListener implements ServletContextListener {
    
    	@Override
    	public void contextDestroyed(ServletContextEvent arg0) {
    		// TODO Auto-generated method stub
    		LogHelper.info("web stop!");
    		System.out.println("dao++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
    	}
    
    	@Override
    	public void contextInitialized(ServletContextEvent sce) {
    		// TODO Auto-generated method stub
    		// SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
    		WebApplicationContextUtils.getRequiredWebApplicationContext(sce.getServletContext())
    				.getAutowireCapableBeanFactory().autowireBean(this);//加上这一句
    		LogHelper.info("web start!");
    		System.out.println("dao++++"+dao.count());
    		LogHelper.info("web start! finish");
    	}
    
    
    	@Autowired
    	private ApplicationMetricsDao dao;
    }
    

      原文地址:https://blog.csdn.net/flymu0808/article/details/50835064

  • 相关阅读:
    重回大一
    20071027我以为我很大度
    凌晨三点
    山洞爱情
    JQuery上传插件Uploadify使用详解
    jquery ui layout
    win2003下direct的问题
    Aptana一些快键用法
    IE、Firefox、Chrome 的JS代码兼容注意事项
    2011学习计划
  • 原文地址:https://www.cnblogs.com/goldenVip/p/9213685.html
Copyright © 2011-2022 走看看