当前位置: 首页 > 工具软件 > Audit4j > 使用案例 >

log4j启动报错问题解决

袁致远
2023-12-01

项目用tomcat启动时,控制台报如下错误,虽然不影响业务正常使用,但还是要把它解决。

"org.apache.log4j.ConsoleAppender" object is not assignable to a "org.apache.log4j.Appender" variable

Could not instantiate appender named "Console".

log4j:ERROR A "org.apache.log4j.ConsoleAppender" object is not assignable to a "org.apache.log4j.Appender" variable.
log4j:ERROR The class "org.apache.log4j.Appender" was loaded by 
log4j:ERROR [org.apache.catalina.loader.StandardClassLoader@1175e2db] whereas object of type 
log4j:ERROR "org.apache.log4j.ConsoleAppender" was loaded by [WebappClassLoader
  context: /ifs_core
  delegate: false
  repositories:
    /WEB-INF/classes/
----------> Parent Classloader:
org.apache.catalina.loader.StandardClassLoader@1175e2db
].
log4j:ERROR Could not instantiate appender named "Console".
log4j:ERROR A "org.apache.log4j.DailyRollingFileAppender" object is not assignable to a "org.apache.log4j.Appender" variable.
log4j:ERROR The class "org.apache.log4j.Appender" was loaded by 
log4j:ERROR [org.apache.catalina.loader.StandardClassLoader@1175e2db] whereas object of type 
log4j:ERROR "org.apache.log4j.DailyRollingFileAppender" was loaded by [WebappClassLoader
  context: /ifs_core
  delegate: false
  repositories:
    /WEB-INF/classes/
----------> Parent Classloader:
org.apache.catalina.loader.StandardClassLoader@1175e2db
].
log4j:ERROR Could not instantiate appender named "R".
log4j:ERROR A "org.apache.log4j.DailyRollingFileAppender" object is not assignable to a "org.apache.log4j.Appender" variable.
log4j:ERROR The class "org.apache.log4j.Appender" was loaded by 
log4j:ERROR [org.apache.catalina.loader.StandardClassLoader@1175e2db] whereas object of type 
log4j:ERROR "org.apache.log4j.DailyRollingFileAppender" was loaded by [WebappClassLoader
  context: /ifs_core
  delegate: false
  repositories:
    /WEB-INF/classes/
----------> Parent Classloader:
org.apache.catalina.loader.StandardClassLoader@1175e2db

解决方法:

这种情况多半的jar包冲突导致,发现项目中有log4j-1.2.16.jar,也有log4j-2.3.jar,排除log4j-1.2.16.jar后问题解决。

 

在此安利下IDEA插件Maven Helper,解决jar包冲突相当方便。

 

参考:https://www.oschina.net/question/271728_172103

 类似资料: