我看起来是春天的3.05源码,我找到了这个类
public class ContextLoaderListener extends ContextLoader implements ServletContextListener{
private ContextLoader contextLoader;
public void contextInitialized(ServletContextEvent event){
if(this.contextLoader == null){
this.contextLoader = this;
}
this.contextLoader.initWebApplicationContext(event.getServletContext());
}
}
为什么要使用contextLoader字段,为什么不使用this.initWebApplicationContext(event.getServletContext());?
使用有什么好处吗?
答案 0 :(得分:3)
我不知道您在哪里找到该代码,但是Spring 3.0.5 ContextLoaderListener
的来源(例如,请参阅here)有以下代码:
public void contextInitialized(ServletContextEvent event) {
this.contextLoader = createContextLoader();
if (this.contextLoader == null) {
this.contextLoader = this;
}
this.contextLoader.initWebApplicationContext(event.getServletContext());
}
你遗漏了方法的第一行!