spring boot 中 log4j2 日志无法加载(Feature 'http://apache.org/xml/features/xinclude' is not recognized.)

Spring boot 1.5.14 版本中使用 log4j2 日志,在 eclipse 中可以打印日志,但是打包成 war 后,直接运行无法将日志输出到日志文件,配置的 log4j2-spring.xml 没有被加载。
输出错误 :

ERROR StatusLogger Error parsing jar:file:/D:/KDR/xx.war!/WEB-INF/classes!/log4j2.xml
 javax.xml.parsers.ParserConfigurationException: Feature 'http://apache.org/xml/features/xinclude' is not recognized.

这个错误无法直接看到,如果使用 log4j2-spring.xml 作为配置文件,因为被 spring boot 捕捉了,没有输出到控制台,我原来以为是打包成 war 格式无法使用 log4j2-spring.xml 作为配置文件,所以又添加了一个 log4j2.xml 作为配置文件,然后使用 java -jar 运行的时候就看到了上面的错误。
但是这个错误死活搜索不到,找了好久,突然在 stackoverflow 搜索到一个类似的错误,说是 Issue http://apache.org/xml/features/xinclude testing log4j 2,里面说是 xercesImpl-2.6.2.jar 这个包的错误,更新或是删除就好,我一查自己的 pom.xml 果然,有这个包,是 2.6.0 版本,果断升级到了 2.11.0 版本,然后,错误就解决了。
这个错误卡了我一天多,查到底层代码了都,还是百度解决的,xercesImpl 是解析 xml 文件的,而配置文件正好是 xml ,真是悲剧。
如果有其他地方也报这个错误,那么也可能是 xercesImpl 版本问题,升级就好。

引用:

https://stackoverflow.com/questions/27860361/issue-http-apache-org-xml-features-xinclude-testing-log4j-2

猜你喜欢

转载自blog.csdn.net/chenfei2341/article/details/80936786