首页 > 代码库 > contextLoaderListener

contextLoaderListener

contextLoaderListener的作用,在启动的时候,自动装载applicationcontext.xml文件。

contextloaderListener实现了servletContextListener接口,在web.xml中配置这个方法,在tomcat启动时就会默认执行它实现的方法。

contextLoaderListener中关联了contextLoader这个类,所以整个加载配置过程由contextLoader来完成,

部署applicationcontext.xml,如果不写任何配置信息,那么默认路径是WEB_INF/Applicationcontext.xml

如果是自定义路径名,那么可以在web.xml中加上contextconfigLocation这个context参数。

<context-param>

  <param-name>contextconfigLocation</param-name>

  <param-value>

    WEB_INF/classes/applicationcontext*.xml

  </param-value>

</context-param>

applicationcontext*.xml通配符,匹配所有以applicationContext开头,.xml结尾的文件。

 

contextLoaderListener