webAppRootKey作用
来源:互联网 发布:康明斯诊断软件下载 编辑:程序博客网 时间:2024/04/30 01:23
不过还是有几个不太方便的地方:
1 Log4j的配置文件修改了之后必须重启才能生效
2 配置文件只能放在WEB-INF/classes
Spring对于Log4j有了更好的增强,配置文件修改后不需要重启,不用再放到WEB-INF/classes目录下。
参数webAppRootKey如果只有一个应用用了Spring对Log4J的增强,则可以不用设置;否则一定要进行设置。
web.xml中webAppRootKey
------------------------------------------------------------------------------------------------
1、 web.xml配置
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>webapp.root</param-value>
</context-param>
"webapp.root"这个字符串可以随便写任何字符串。如果不配置默认值是"webapp.root"。
可以用System.getProperty("webapp.root")来动态获项目的运行路径。
一般返回结果例如:/usr/local/tomcat6/webapps/项目名
定义以后,在Web Container启动时将把ROOT的绝对路径写到系统变量里。
然后log4j的配置文件里就可以用${webName.root }来表示Web目录的绝对路径,把log文件存放于webapp中。
此参数用于后面的“Log4jConfigListener”-->
2、解决以下报错
部署在同一容器中的Web项目,要配置不同的<param-value>,不能重复,否则报类似下面的错误:
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的功能
一般配置类型下面的例子:
- <!-- 加载Log4J 配置文件 -->
- <context-param>
- <param-name>log4jConfigLocation</param-name>
- <param-value>WEB-INF/conf/log4j.properties</param-value>
- </context-param>
- <context-param>
- <param-name>log4jRefreshInterval</param-name>
- <param-value>3000</param-value>
- </context-param>
- <listener>
- <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
- </listener>
4、在运行时动态的找出项目的路径
在log4j.properties配置文件,就可以按下面的方式使用${webapp.root}:log4j.appender.file.File=${webapp.root}/WEB-INF/logs/sample.log
就可以在运行时动态的找出项目的路径
- webAppRootKey作用
- webAppRootKey
- webAppRootKey
- webAppRootKey
- web.xml配置文件中的webAppRootKey作用
- web.xml中webAppRootKey
- web.xml中webAppRootKey
- log4j配置webAppRootKey
- web.xml中webAppRootKey
- web.xml中webAppRootKey
- web.xml配置webAppRootKey
- web.xml中webAppRootKey
- web.xml中webAppRootKey
- web.xml中webAppRootKey
- web.xml中webAppRootKey
- web.xml中webAppRootKey
- web.xml中webAppRootKey
- web.xml中webAppRootKey
- C# 快速创建线程
- 利用UIImageJPEGRepresentation与UIGraphicsBeginImageContext进行图片压缩的简单比较
- Android SwipeRefreshLayout 官方下拉刷新控件介绍
- Linux Ubuntu下安装PPA源软件
- linux并发服务器模型设计
- webAppRootKey作用
- android中遇到的java反射
- MAC快捷键汇总
- Struts2基础
- 父子进程ID和进程收养问题(init与upstart)
- arcgis 进行中文分类标注相关说明
- 微信扫码支付
- Android Studio 快捷键
- 数据库sql中in和exists的区别