当前位置: 代码迷 >> Java Web开发 >> 系统启动时的spring注入…解决思路
  详细解决方案

系统启动时的spring注入…解决思路

热度:5808   发布时间:2013-02-25 21:07:10.0
系统启动时的spring注入……
我在系统启动时,想通过ServletContextListener加载数据库的常用数据,以下是部分代码
public class initSystemListener implements ServletContextListener
{
private ServletContext context = null;
public void contextDestroyed(ServletContextEvent arg0)
{
// TODO Auto-generated method stub

}
public void contextInitialized(ServletContextEvent arg0)
{
context = arg0.getServletContext();
Configer.getInstance("systemConfig").loadSysConfig();
Configer.virtualRoot = context.getInitParameter("virtualRoot");
}
}
这里Configer是一个普通bean,我想在这个bean中注入一个service,见下
public class Configer
{
public static String virtualRoot;
private ICommon sysConfigService;
public void setSysConfigService(ICommon sysConfigService)
{
this.sysConfigService = sysConfigService;
}
我也作了相应配置
<bean id="configer" class="com.family168.init.Configer" >
<property name="sysConfigService">
  <ref bean="sysConfigService" />
</property>
</bean>
可是通过断点跟踪发现,根本没有执行setSysConfigService方法,sysConfigService 一直为null,我这里哪里发生了问题……
 既然有spring,为什么不extends ContextLoaderListener呢<ref bean="sysConfigService" />
sysConfigService配置了么?是不是这里的sysConfigService就是空的?
  相关解决方案