Web. XML Webapprootkey
1. Web. XML Configuration
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>webapp.root</param-value>
</context-param>
The string "Webapp.root" can be arbitrarily written in any string. If you do not configure the default value is "Webapp.root".
You can use System.getproperty ("Webapp.root") to dynamically get the project's running path.
General return results For example:/usr/local/tomcat6/webapps/project name
2. Resolve the following error
Web projects deployed in the same container, to be configured with different <param-value>, cannot be duplicated, otherwise the report resembles the following error:
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 fil Es!
This means that the "webapp.root" key already points to item 1 and cannot point to item 2.
3. Loading mode
Spring works by Org.springframework.web.util.WebAppRootListener the listener to run the project path.
However, if the Org.springframework.web.util.Log4jConfigListener listener is already configured in Web. XML,
You do not need to configure the Webapprootlistener. Because Log4jconfiglistener already contains the functions of Webapprootlistener.
General configuration Type the following example: XML code <!--load log4j configuration file--<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>
<!--configured with a listener, you can also configure Servlet:-->
<!--
<servlet>
<servlet-name>log4j</ servlet-name>
<servlet-class>
org.springframework.web.util.Log4jConfigServlet
</ servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
log4jrefreshinterval in Web. XML
Log4jrefreshinterval is 3000 to open a watchdog thread to scan for changes in configuration files every 3 seconds.
The ability to dynamically modify the Log4j.properties key, the container scans the log4j configuration file every 3 seconds.
4. Dynamically identify the path to the project at run time
In the log4j.properties configuration file, you can use ${webapp.root} as follows:
Log4j.appender.file.file=${webapp.root}/web-inf/logs/sample.log
You can dynamically find the path to the project at run time