在Servlet(或者Filter,或者Listener)中使用spring的IOC容器
2006-09-22 19:46
513 查看
在servlet或者filter或者Listener中使用spring的IOC容器的方法是:
WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());
由于spring是注入的对象放在ServletContext中的,所以可以直接在ServletContext取出WebApplicationContext 对象:
WebApplicationContext webApplicationContext = (WebApplicationContext) servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
事实上WebApplicationContextUtils.getWebApplicationContext方法就是使用上面的代码实现的,建议使用上面上面的静态方法
WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());
由于spring是注入的对象放在ServletContext中的,所以可以直接在ServletContext取出WebApplicationContext 对象:
WebApplicationContext webApplicationContext = (WebApplicationContext) servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
事实上WebApplicationContextUtils.getWebApplicationContext方法就是使用上面的代码实现的,建议使用上面上面的静态方法
相关文章推荐
- 在Servlet(或者Filter,或者Listener)中使用spring的IOC容器
- 在Servlet(或者Filter,或者Listener)中使用spring的IOC容器
- 在Servlet(或者Filter,或者Listener)中使用spring的IOC容器
- (转)在Servlet(或者Filter,或者Listener)中使用spring的IOC容器
- 在Servlet(或者Filter,或者Listener)中使用spring的IOC容器
- 在Servlet(或者Filter,或者Listener)中使用spring的IOC容器
- 在servlet(或者filter或者listener)中使用spring的IOC容器
- 在Servlet(或者Filter,或者Listener)中使用spring的IOC容器
- 在listener或者工具中使用spring容器中的bean实例
- 在SpringBoot中使用 Servlet Filter Listener
- 在Servlet Filter中使用Spring容器
- 在servlet中或者在filter中获取spring容器中的bean
- 如何让servelt和Filter注入到spring容器或者在servlet中调用spring中的bean
- Spring Boot中Servlet&Filter&Listener&Interceptor的使用
- Spring Boot使用Servlet、Filter或Listener的方式
- springboot 使用Servlet,Filter,Listener的方法
- spring-boot如何定义一个servlet,filter,listener
- 使用 Spring 容器管理 Filter
- servlet,filter, listener, interceptor 区别与联系(前俩天使用了Filter过滤器,特在此整理下)