獲取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

相關文章
相關標籤/搜索