log4j webAppRootKey

1 在web.xml配置

<context-param>
<param-name>webAppRootKey</param-name>
<param-value>webName.root</param-value>
</context-param>

可以用System.getProperty("webName.root")来获取属性值。在Eclipse调试Web项目时,项目的路径是一个临时路径,不在真正的路径下,可以通过上述语句打印出属性值,来看看临时项目路径在哪里

2、Spring通过 org.springframework.web.util.WebAppRootListener 这个监听器来压入项目路径。但是如果在web.xml中已经配置了 org.springframework.web.util.Log4jConfigListener
这个监听器,则不需要配置WebAppRootListener了。因为Log4jConfigListener已经包含了WebAppRootListener的功能

3、部署在同一容器中的Web项目,要配置不同的<param-value>,不能重复

4、如果配置了
log4j.appender.file.File=${webName.root}/WEB-INF/logs/sample.log

log4j会自己自动建立logs目录, 不需要手工显式建立空的logs目录


常见错误:多个工程目录下的web.xml文件的<param-value>webName.root</param-value>相同,就算在tomcat的conf下配置不同的名,例如配置atcs2.xml指向另外一个工程目录,但是恰巧那个工程下的web.xml里面也配置相同的webAppRootKey,那么将会出现其中一个工程不能够访问的问题。
网页出现经典的The requested resource (/webName/) is not available错误!

问题发现方法:在myEclipse下配置log4j,之后会将一些不会报出来的错误亦会报出来,根据信息就可以发现是相同的webAppRootKey覆盖问题。在此我的log4j的报错信息:
Web app root system property already set to different value: 'atcs.root' = [D:\workspace2\Huadu_Atcs3\WebContent\] instead of [D:\WorkSpace\Huadu_Atcs3\WebContent\] - Choose unique values for the 'webAppRootKey' context-param in your web.xml files!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://JAVA.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <display-name>springMVC</display-name> <welcome-file-list> <welcome-file>/WEB-INF/jsp/login.jsp</welcome-file> </welcome-file-list> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext-mybatis.xml</param-value> </context-param> <filter> <filter-name>encodingFilter</filter-name> <filter-class> org.springframework.web.filter.CharacterEncodingFilter </filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <servlet> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:springmvc-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>classpath:log4j.properties</param-value> </context-param> <context-param> <param-name>webAppRootKey</param-name> <param-value>keshe_C12_09.root</param-value> </context-param> <listener> <listener-class> org.springframework.web.util.Log4jConfigListener </listener-class> </listener> </web-app>
07-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值