2007-01-20
如何在spring项目里用jndi方式获得beanfactory
题目说的有点不太清楚,讲讲实际的问题吧。
我使用spring在web.xml中使用了
org.springframework.web.context.ContextLoaderListener
装入了所有的bean实例可以正常使用。
但是现在程序里有一个要求可以动态的装入各个服务bean,所有要获得beanfactory才能得到。我在想spring使用contextloaderlistener时,是否会将装入的beanfactory挂到jndi树上呢,还是怎么获得,请各位!谢谢
排除自己重新new一个beanfactory实例,那是重复的加载。。
我使用spring在web.xml中使用了
org.springframework.web.context.ContextLoaderListener
装入了所有的bean实例可以正常使用。
但是现在程序里有一个要求可以动态的装入各个服务bean,所有要获得beanfactory才能得到。我在想spring使用contextloaderlistener时,是否会将装入的beanfactory挂到jndi树上呢,还是怎么获得,请各位!谢谢
排除自己重新new一个beanfactory实例,那是重复的加载。。
评论
cljhyjs
2007-08-07
解决方法如下:
public class SpringInitListener implements javax.servlet.ServletContextListener {
private ContextLoader contextLoader;
/**
* Initialize the root web application context.
*/
public void contextInitialized(ServletContextEvent event) {
this.contextLoader = createContextLoader();
WebApplicationContext context = this.contextLoader
.initWebApplicationContext(event.getServletContext());
SpringBeanFactory.setAppContext(context);
}
/**
* Create the ContextLoader to use. Can be overridden in subclasses.
*
* @return the new ContextLoader
*/
protected ContextLoader createContextLoader() {
return new ContextLoader();
}
/**
* Return the ContextLoader used by this listener.
*/
public ContextLoader getContextLoader() {
return contextLoader;
}
/**
* Close the root web application context.
*/
public void contextDestroyed(ServletContextEvent event) {
if (this.contextLoader != null) {
this.contextLoader.closeWebApplicationContext(event
.getServletContext());
}
}
}
public class SpringInitListener implements javax.servlet.ServletContextListener {
private ContextLoader contextLoader;
/**
* Initialize the root web application context.
*/
public void contextInitialized(ServletContextEvent event) {
this.contextLoader = createContextLoader();
WebApplicationContext context = this.contextLoader
.initWebApplicationContext(event.getServletContext());
SpringBeanFactory.setAppContext(context);
}
/**
* Create the ContextLoader to use. Can be overridden in subclasses.
*
* @return the new ContextLoader
*/
protected ContextLoader createContextLoader() {
return new ContextLoader();
}
/**
* Return the ContextLoader used by this listener.
*/
public ContextLoader getContextLoader() {
return contextLoader;
}
/**
* Close the root web application context.
*/
public void contextDestroyed(ServletContextEvent event) {
if (this.contextLoader != null) {
this.contextLoader.closeWebApplicationContext(event
.getServletContext());
}
}
}
- 浏览: 2053 次
- 性别:

- 来自: 上海

- 详细资料
搜索本博客
我的相册
1
共 1 张
共 1 张
最近加入圈子
最新评论
-
生产消费问题编码
楼上说了,用条件队列协调,你描述的不是很清楚,不过看情况就得用条件队列,可以传统 ...
-- by dennis_zane -
生产消费问题编码
自己想了一个办法,大家看行不行 private static boolean ...
-- by cljhyjs -
讨论一下大用户量应用客户 ...
cljhyjs 写道 最近公司正在做一个项目,该项目的客户端应用相当广泛,类 ...
-- by jiyanliang -
讨论一下大用户量应用客户 ...
用UDP,客户端定时发送心跳包到服务器避免路由器删除NAT的SESSION,需要 ...
-- by ydsoft -
讨论一下大用户量应用客户 ...
没人回答,自己up一下!看了banq的关于建立高性能聊天室文章,似有收获
-- by cljhyjs






评论排行榜