This problem has afflicted me for a whole day, and I hereby write to help the little friends of the future to make less detours.
I'll describe the environment first, and you'll see if it's similar to your situation.
Spring and log4j are used in the project, Org.springframework.web.util.Log4jConfigListener monitoring is used, ${webapp.root is configured in Log4j.properties} To get the Webapprootkey configured in Web. Xml. The approximate relevant code is as follows:
Xml:
<context-param> <param-name>webAppRootKey</param-name> <param-value>szweb.root</ param-value></context-param> <context-param> <param-name>log4jconfiglocation</ Param-name> <param-value>/web-inf/classes/log4j.properties</param-value></context-param > <context-param> <param-name>log4jRefreshInterval</param-name> < Param-value>60000</param-value></context-param> <listener> <listener-class> Org.springframework.web.util.log4jconfiglistener</listener-class></listener>
Log4j.properties:
Log4j.appender.logfile_error. File=${webapp.root}/web-inf/logs/systemerror.log
Online streaming results in setfile (null,..) The reason is
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
Need to be set into classpath:log4j.properties
And in my project, the reason I found out is:
The order of execution of the listener results in ...
The order of execution in Web. XML is such a context-param-->listener-->filter-->servlet, and listener is executed in the order you write ...
My project exists ab two Listener,alistener in front, which has done some system business parameters initialization, Blistener is Log4jconfiglistener, originally is no problem, but a in the operation of the log, So in the Blistener has not yet come into force before the request log4j began to do log processing, so log4j classmate went to find their own configuration file, and then found that there is a ${webapp.root}, and then it went to the property inside the system to find, Found no and then an error ... Why not? Because Blistener actually reads the Servlet.realpath, and then associates the Webapprootkey you set with the Realpath, and saves it to the system's property ... As a result B had not had time to dry, a went to find ...
I found the reason ... (Before Google ... The degree Niang all asked ... No one, like me, eventually looked at what the Log4jconfiglistener had done, and then remembered that it might have been the order of execution .
All right, the end of the scatter flower
Log4j.properties Read Webapp.root value failed, resulting in setfile (null,..) Solutions for