posts - 122,  comments - 25,  trackbacks - 0
在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方法就是使用上面的代码实现的,建议使用上面上面的静态方法
posted on 2007-04-25 17:08 josson 阅读(504) 评论(0)  编辑  收藏 所属分类: Spring

只有注册用户登录后才能发表评论。


网站导航:
 
<2007年4月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

常用链接

留言簿(3)

随笔分类

随笔档案

收藏夹

搜索

  •  

最新评论

阅读排行榜

评论排行榜