spring ApplicationContext对于jdk1.4的支持与如何处理
error create bean问题
项目使用spring+struts,服务器用WebSphere 5,使用的是JDK1.4,主要使用了AOP注入方式,目前需要在web项目中使用一个线程处理内容,使用了plugIn来启动一个线程,但是在jdk1.4中,又无法使用ApplicationContext这个东东,不知道能不能用其他的方式来处理。
贴代码:
public class ThreadStartPlugIn implements PlugIn {
private Logger log = Logger.getLogger(this.getClass());
public void destroy() {
}
public void init(ActionServlet arg0, ModuleConfig arg1)
throws ServletException {
ApplicationContext ctx = new FileSystemXmlApplicationContext(
"classpath:/applicationContext.xml");
FileManageThread fileManageThread=(FileManageThread) ctx.getBean("fileManageThread");
thread.start();
// log.debug("解析线程已经启动!");
}
}
XML:
<bean id="fileManageThread"
class="execl.com.gohigh.execlmanage.FileManageThread">
<property name="execlTransactionManage">
<ref bean="execlTransactionManage" />
</property>
</bean>
问题的关键部分:在JDK1.4下,如何在类里面获取到上下文注入的对象
/***************************************************************************************************************/
这个代码是有问题的, 这样会再加载一次applicationContext.xml. (比如: web容器加载了一次, 你里面有加载一次)
除非你就是要自己再加载一次. 应该没这个要求把.
不能明白为什么1.4不能使用ApplicationContext.
你可以写一个类实现ApplicationContextAware, 从而得到ApplicationContext, 并把ApplicationContext写到这个类的static字段里面去, 这样, 外面其他的类就可以很简单的得到ApplicationContext.