嵌入在Eclipse

时间:2016-05-20 08:19:10

标签: eclipse maven tomcat log4j web.xml

我目前遇到了我需要的情况 1)具有外部log4j.properties 2)log4j.properties的位置在web.xml中配置为属性占位符,从POM读取属性的值。 3)占位符在构建时填充,即.war创建时

到目前为止,这么好 - 应用程序将log4j定位在POM中指定的位置并生成日志文件。但是,这仅在将应用程序作为.war部署到独立Tomcat实例时才有效。下一个要求是能够将它部署到Eclipse中嵌入的Tomcat,据我所知,这个步骤并不涉及Maven。有没有办法强制web.xml在部署到嵌入式Tomcat实例时填充其属性占位符?

提前致谢

安格斯

1 个答案:

答案 0 :(得分:0)

是的,我最终想出了一个解决方案。包括以下配置:

的web.xml

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

<context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>${log4j.properties.location}</param-value>
</context-param>

<context-param>
    <param-name>log4jExposeWebAppRoot</param-name>
    <param-value>false</param-value>
</context-param>

<context-param>
    <param-name>log4jRefreshInterval</param-name>
    <param-value>60000</param-value>
</context-param>

context.xml中:

<Parameter name="log4j.properties.location" value="file:/usr/local/etc/xxxxxxxxx/xxxxxxxxxxxxx/log4j.properties"/>

你应该好好去。