您的位置:首页 > 移动开发 > WebAPP

(转)web.xml中webAppRootKey

2016-07-09 11:50 399 查看
---恢复内容结束---

web.xml中webAppRootKey
------------------------------------------------------------------------------------------------
1、 web.xml配置

webAppRootKey
webapp.root

"webapp.root"这个字符串可以随便写任何字符串。如果不配置默认值是"webapp.root"。

可以用System.getProperty("webapp.root")来动态获项目的运行路径。
一般返回结果例如:/usr/local/tomcat6/webapps/项目名

2、解决以下报错
部署在同一容器中的Web项目,要配置不同的,不能重复,否则报类似下面的错误:
Web app root system property already set to different value: 'webapp.root' = [/home/user/tomcat/webapps/project1/] instead of [/home/user/tomcat/webapps/project2/] - Choose unique values for the 'webAppRootKey' context-param in your web.xml files!
意思是“webapp.root”这个key已经指向了项目1,不可以再指向项目2.

3、加载方式
Spring通过org.springframework.web.util.WebAppRootListener 这个监听器来运行时的项目路径。
但是如果在web.xml中已经配置了 org.springframework.web.util.Log4jConfigListener这个监听器,
则不需要配置WebAppRootListener了。因为Log4jConfigListener已经包含了WebAppRootListener的功能
一般配置类型下面的例子:
Xml代码

log4jConfigLocation
WEB-INF/conf/log4j.properties

log4jRefreshInterval
3000

org.springframework.web.util.Log4jConfigListener

4、在运行时动态的找出项目的路径
在log4j.properties配置文件,就可以按下面的方式使用${webapp.root}:
log4j.appender.file.File=${webapp.root}/WEB-INF/logs/sample.log
就可以在运行时动态的找出项目的路径
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: