首页 > 代码库 > Spring监听器配置

Spring监听器配置

使用spring框架时如果同时使用org.springframework.web.util.Log4jConfigListener监听器,那么在web.xml中的监听器的注册顺序为org.springframework.web.context.ContextLoaderListener在后,org.springframework.web.util.Log4jConfigListener在前,否则就回出现如下警告:

log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.

我们在spring的api文档中可以看到下面一段说明:

Bootstrap listener to start up Spring‘s root WebApplicationContext. Simply delegates to ContextLoader.

This listener should be registered after Log4jConfigListener in web.xml, if the latter is used.

正确配置如下:

<listener>      <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>  </listener>  <listener>      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  </listener>  

 

Spring监听器配置