日期:2014-05-17  浏览次数:20624 次

系统启动时的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,我这里哪里发生了问题……
 
------解决方案--------------------
<ref bean="sysConfigService" />
sysConfigService配置了么?是不是这里的sysConfigService就是空的?

------解决方案--------------------
既然有spring,为什么不extends ContextLoaderListener呢