在我的应用程序中,我使用Log4j进行日志记录.目前我将log4j.xml放在WEB-INF/classes中.以下是我用来加载log4j.xml文件的配置.
<!-- language: xml -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
Run Code Online (Sandbox Code Playgroud)
现在我需要将log4j.xml文件放在war文件之外.该位置很可能是JBOSS_HOME/server/default/deploy/settings.在设置目录中,我需要放置我的log4j.xml.
我尝试通过编辑run.bat设置jboss类路径加载它,如下所示设置JBOSS_CLASSPATH =%RUN_CLASSPATH%;%JBOSS_HOME%\ server\default\deploy\settings我在web.xml下面使用
<!-- language: xml -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:/log4j.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
Run Code Online (Sandbox Code Playgroud)
但它在部署应用程序时抛出异常.例外是
java.lang.IllegalArgumentException: Invalid 'log4jConfigLocation' parameter: class path resource [/log4j.xml] cannot be resolved to URL because it does not exist
现在我的问题是如何加载它.
mat*_*tis 10
请记住在路径前添加"file://",否则它将在webapp文件夹中搜索.
以下示例适用于我.
<web-app>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>file://${MY_ENV_VAR}log4j.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
</web-app>
Run Code Online (Sandbox Code Playgroud)
我有同样的例外.
我用过这段代码:
<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>
Run Code Online (Sandbox Code Playgroud)
执行时,此异常消失了:
mvn clean install
你可以简单地声明log4j配置的位置,如下所示:
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>${JBOSS_HOME}/server/default/deploy/settings/log4j.xml</param-value>
</context-param>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
30458 次 |
| 最近记录: |