升级log4j2,tomcat--7.0.16 启动就OOM,蛋疼的问题

时间:2022-06-10 21:48:53

升级log4j2 ,官网说要web.xml里的<web-app> version 属性改成3.0,发现改了之后,一起动就报错OOM,

Exception in thread "main" 
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "main"


发现改成2.5就没事:

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                      http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  version="2.5"

  >  


,或者加一个属性  metadata-complete=true 也没事:

  <web-app xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                      http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
  version="3.0"
  metadata-complete="true"
  >  


或者,换成 tomcat-7.0.81也没事,

真是日了狗了,这种问题网上没答案 只有靠自己研究了,折腾了好长时间


这个属性的作用如下:

Attribute : metadata-complete
The metadata-complete attribute defines whether this deployment descriptor and other related 
 deployment descriptors for this module (e.g., web service descriptors) are complete, or whether the 
 class files available to this module and packaged with this application should be examined for 
 annotations that specify deployment information. If metadata-complete is set to "true", the 
 deployment tool must ignore any annotations that specify deployment information, which might be 
 present in the class files of the application. If metadata-complete is not specified or is set to "false", 
 the deployment tool must examine the class files of the application for annotations, as specified by 
 the specifications.



猜测 是 2.5 没有采用java注解配置servlet,listener,filter....的特性,tomcat--7.0.16不会扫描java类的class,version=3.0 加上一个metadata-complete=true  属性也能阻止扫描

改成3.0  tomcat--7.0.16就会去扫描这些有servlet注解的 class,可能在这个过程中导致了OOM

而 tomcat--7.0.81 可能修复了这个问题



好复杂。。。。。。。。。。。。。。。。。