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

Servletapp

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

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

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

相关文章
相关标签/搜索