【发布时间】:2013-08-30 13:22:00
【问题描述】:
我可以使用以下配置在我的 Spring 应用程序中读取属性文件(注意类路径中的通配符)
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>classpath*:*/**/test*.properties</value>
</property>
但是,当我使用相同的通配符模式来使用 web.xml 中的 org.springframework.web.util.Log4jConfigListener 指定自定义 Log4j 属性文件时,如下所示,它会因讨厌的 FileNotFoundException 而失败,并且 Log4j 未初始化。
谁能帮我解决这个问题,并指出我在这里缺少什么。
web.xml
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath*:*/**/customLog4j*.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
P.S.:我知道财产占位符,即。 ${SOME_PLACE_HOLDER}(我们可以用相应的系统/环境属性替换占位符值)在我的情况下无法应用,因为我们无法控制设置此类系统/环境属性并且必须使用通配符解析自定义 log4j 属性的路径。
【问题讨论】:
-
不这么认为 -
org.springframework.web.util.Log4jConfigListener是使用log4jConfigLocation的 spring 框架的一部分,与任何特定的 Servlet 容器无关 -
Log4jConfigListener 使用 Log4jWebConfigurer 加载配置。查看文档,了解什么是有效的以及如何配置 link
-
@madhav-turangi thnx 很有帮助:)
标签: java spring spring-mvc properties classpath