(web.xml)对org.springframework.web.util.WebAppRootListener理解与应用

在慢慢对web.xml中的内容学习过程中发现这样的配置:

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

<listener>
	<listener-class>org.springframework.web.util.WebAppRootListener</listener-class>
</listener>

如果配置了webAppRootKey,就可以用System.getProperty("webapp.root")来动态获项目的运行路径。一般返回结果例如:/usr/local/tomcat/webapps/项目名。当然"webapp.root"这个字符串可以随便写任何字符串。如果不配置默认值是"webapp.root"。比如在log4j.properties配置文件,就可以按下面的方式使用${webapp.root}:
 log4j.appender.file.File=${webapp.root}/logs/xxx.log 就可以在运行时动态的找出项目的路径。

参考:

http://elf8848.iteye.com/blog/2008595

猜你喜欢

转载自yeshuang.iteye.com/blog/2343999