2006-09-18
Web中使用普通类得到applicationContext
用一个类来存放applicationContext:
然后写一个servlet,继承自org.springframework.web.context.ContextLoaderServlet,并配置web.xml,让它在tomcat启动时自动运行。然后在它的init方法中,加入如下的代码:
- public class ContextHolder {
- private final static ContextHolder instance = new ContextHolder();
- private ApplicationContext ac;
- private ContextHolder() {
- }
- public static ContextHolder getInstance() {
- return instance;
- }
- public synchronized void setApplicationContext(ApplicationContext ac) {
- this.ac = ac;
- }
- public ApplicationContext getApplicationContext() {
- return ac;
- }
- }
然后写一个servlet,继承自org.springframework.web.context.ContextLoaderServlet,并配置web.xml,让它在tomcat启动时自动运行。然后在它的init方法中,加入如下的代码:
- WebApplicationContext context = WebApplicationContextUtils.
- getWebApplicationContext(this.getServletContext());
- ContextHolder.getInstance().setApplicationContext(context);
发表评论
我的相册
sina
共 3 张
共 3 张
最近加入圈子
链接
最新评论
-
羡慕,那你也加入啊
和我的拒信一模一样。哎
-- by niwtsew -
web环境下开发quartz简易 ...
你写的很好。我的是在rcp下面是用quartz还得自己摸索..........
-- by futionbai -
Starting Struts2中文版已 ...
呵呵,希望大家可以喜欢
-- by dearwolf -
Starting Struts2中文版已 ...
正在看这本书!! 哈哈
-- by kanokano -
CSDN英雄大会上,跟苏某翻 ...
我只想到。。。这么年轻就有仔了,好可怜阿。。。。
-- by akane







评论排行榜