Spring监听器配置

喜欢而已 提交于 2019-11-27 23:51:28

使用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>  

  

转载于:https://www.cnblogs.com/JAYIT/p/4100846.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!