获取aplicationContext对象,从而获取任何注入的对象

Servlet

方法一: ServletContext 取出 Spring容器上下文

ApplicationContext applicationContext = (ApplicationContext) this.getServletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);

方法二: ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());

 

posted @ 2016-11-16 20:28  apache-xinge  阅读(514)  评论(0编辑  收藏  举报