Invalid ‘log4jConfigLocation’ parameter: class path resource [log4j.properties] cannot be resolved

今天建了一个多模块的maven项目, 在web.xml中配置了log4j如下:

<context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>classpath*:log4j.properties</param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>

我想着把log4j.properties 放在配置工程中去,于是classpath后面加了*号。

但是就爆了上面的错误提示找不到log4j.properties。

于是把log4j.properties文件放在web工程的resource下,去掉classpath后面的*, 即就是与web.xml文件要与log4j.properties在同一个工程里,就好了。如下

<context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>classpath:log4j.properties</param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>

注意:在contextConfigLocation中,我是可以使用classpath*:* 从而去寻找jar文件中对应的配置文件。但是log4jConfigLocation不支持这种做法。

更多推荐