寻找spring框架的启动入口 ContextLoaderListener
2014-10-23 16:48
375 查看
spring在web下的入口在配置文件web.xml的监听器中
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:conf/spring/applicationContext.xml</param-value>
</context-param>
上述是在web.xml中的配置信息。
//实现了接口ServletContextListener,也就是说他必须实现contextDestroyed, contextInitialized这两个方法
public class ContextLoaderListener implements ServletContextListener {
private ContextLoader contextLoader;
/**
* Initialize the root web application context.
*/
//Spring框架由此启动, contextInitialized也就是监听器类的main入口函数
public void contextInitialized(ServletContextEvent event) {
this.contextLoader = createContextLoader();
this.contextLoader.initWebApplicationContext(event.getServletContext());
}
/**
* 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.
* @return the current ContextLoader
*/
public ContextLoader getContextLoader() {
return this.contextLoader;
}
/**
* Close the root web application context.
*/
public void contextDestroyed(ServletContextEvent event) {
if (this.contextLoader != null) {
this.contextLoader.closeWebApplicationContext(event.getServletContext());
}
}
}
总的来说这个入口非常简单,所有实现都隐藏在ContextLoader类里,我们在下一篇的内容中讨论ContextLoader,如果你不知道为什么这里是程序的入口,那么复习一下ServletContextListener 接口和监听器的相关知识吧
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:conf/spring/applicationContext.xml</param-value>
</context-param>
上述是在web.xml中的配置信息。
//实现了接口ServletContextListener,也就是说他必须实现contextDestroyed, contextInitialized这两个方法
public class ContextLoaderListener implements ServletContextListener {
private ContextLoader contextLoader;
/**
* Initialize the root web application context.
*/
//Spring框架由此启动, contextInitialized也就是监听器类的main入口函数
public void contextInitialized(ServletContextEvent event) {
this.contextLoader = createContextLoader();
this.contextLoader.initWebApplicationContext(event.getServletContext());
}
/**
* 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.
* @return the current ContextLoader
*/
public ContextLoader getContextLoader() {
return this.contextLoader;
}
/**
* Close the root web application context.
*/
public void contextDestroyed(ServletContextEvent event) {
if (this.contextLoader != null) {
this.contextLoader.closeWebApplicationContext(event.getServletContext());
}
}
}
总的来说这个入口非常简单,所有实现都隐藏在ContextLoader类里,我们在下一篇的内容中讨论ContextLoader,如果你不知道为什么这里是程序的入口,那么复习一下ServletContextListener 接口和监听器的相关知识吧
相关文章推荐
- Spring框架的启动入口 ContextLoaderListener
- maven 工程启动找不到 Spring ContextLoaderListener 的解决办法
- maven 工程启动找不到 Spring ContextLoaderListener 的解决办法
- maven 工程启动找不到 Spring ContextLoaderListener 的解决办法
- maven项目启动报:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener 错误解决方法-杜恩德
- 启动报错:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
- maven 工程启动找不到 Spring ContextLoaderListener 的解决办法
- 启动报错:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
- tomcat启动问题---java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
- 启动项目报Log4jConfigListener或者ContextLoaderListener类找不到
- maven 工程启动找不到 Spring ContextLoaderListener 的解决办法
- maven 工程启动找不到 Spring ContextLoaderListener 的解决办法
- maven 工程启动找不到 Spring ContextLoaderListener 的解决办法
- maven 工程启动找不到 Spring ContextLoaderListener 的解决办法
- 【项目启动】 tomcat启动,项目无法启动,无法正常访问/项目可以启动,报错:java.lang.ClassNotFoundException: ContextLoaderListener
- SpringMvc项目 Tomacat启动错误 ContextLoaderListener
- 启动报错:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
- 本地启动项目,提示web包未加载,ClassNotFound(如ContextLoaderListener)
- maven项目启动报错: java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
- Intellij IDEA 启动项目ClassNotFoundException:org.springframework.web.context.ContextLoaderListener