Java.lang.IllegalStateException:Web App root system property already set to different value error reason and resolution LOG4J

Source: Internet
Author: User

LOG4J is an Apache open source project, through the use of log4j, we can control the log information delivery destination is the console, files, GUI components, even the socket server, NT Event recorder, UNIX syslog daemon, etc. We can also control the output format of each log, and by defining the level of each log information, we can control the log generation process more carefully. Most interesting of all, these can be configured flexibly with a single configuration file, without the need to modify the code of the application.

In fact, I think he is a component that can monitor our web application, so that we can see how our program is running and the related records after the error.

I reported a mistake when I was using it.

Java code
    1. Severity: Exception sending context initialized event to listener instance of class Org.springframework.web.util.Log4jConfi Glistener
    2. Java.lang.IllegalStateException:Web App root system property already set to different value: ' webapp.root ' = [D:\MyEc Lipseproject\.metadata\.me_tcat\webapps\reservationsystem\] instead of [D:\MyEclipseProject\.metadata\.me_tcat\  Webapps\springmvcdemo\]-Choose unique values for the ' Webapprootkey ' Context-param in your web. XML files!

Let's take a look at the configuration of log4j:

Java code
  1. Log4j.rootlogger=info, stdout, logfile
  2. Log4j.appender.stdout=org.apache.log4j.consoleappender
  3. Log4j.appender.stdout.layout=org.apache.log4j.htmllayout
  4. #log4j. appender.stdout.layout.conversionpattern=%d%p [%c]-%m%n
  5. log4j.appender.stdout.layout.conversionpattern=-%m%n
  6. Log4j.appender.logfile=org.apache.log4j.rollingfileappender
  7. Log4j.appender.logfile.file=${webapp.root}/webapp.html
  8. log4j.appender.logfile.maxfilesize=512kb
  9. # Keep three backup files.
  10. log4j.appender.logfile.maxbackupindex=3
  11. # Pattern to Output:date Priority [Category]-message
  12. Log4j.appender.logfile.layout=org.apache.log4j.htmllayout
  13. log4j.appender.logfile.layout.conversionpattern=%d%p [%c]-%m%n
  14. Log4j.logger.com.opensymphony.xwork2=error
  15. # Control Logging for other open source packages
  16. Log4j.logger.org.springframework=error
  17. Log4j.logger.org.quartz=error
  18. Log4j.logger.net.sf.ehcache=error
  19. Log4j.logger.net.sf.navigator=error
  20. Log4j.logger.org.apache.commons=error
  21. Log4j.logger.org.apache.struts=error
  22. Log4j.logger.org.hibernate=debug
  23. # Struts Ognlutil issues unimportant warnings
  24. Log4j.logger.com.opensymphony.xwork2.util.ognlutil=error
  25. Log4j.logger.com.opensymphony.xwork2.ognl.ognlvaluestack=error

Found that there is no problem ah, but, please note ${webapp.root} This variable, with the error hint about a glance, meaning that the Web application root system properties have been set, it is said that the "Webapp.root" This configuration name has been used, no longer use this ,

It also prompts choose unique values for the ' Webapprootkey ' Context-param in your. xml files, which means that we can configure a unique ' Webappro ' in Web. xml Otkey ', so there will be no conflict.

This problem can occur when a Web server deploys multiple applications that use LOG4J, and if configured improperly, this error can really make you depressed and crazy. That's the problem. A Tomcat deploys 2 projects that use log4j.

Then I fix it: press the hint in Web. XML to add

Java code
    1. <context-param>
    2. <param-name>webAppRootKey</param-name>
    3. <param-value>myapp.root</param-value>
    4. </context-param>

Then write ${myapp.root} in the Log4j.properties, as long as the name is not duplicated, it will not produce the Web App root system property already set to different value error. While it is relatively rare to deploy multiple applications on a single server when it is used formally, it is still safe to use, but also to standardize our program-related nomenclature,

${webapp.root} is a good habit to change to ${[application].root}.

Java.lang.IllegalStateException:Web App root system property already set to different value error reason and resolution LOG4J

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.