Spring+SpringMVC+MyBatis+Maven项目中,log4j报错

thexinkewonder 发布于 2020/06/02 15:47
阅读 102
收藏 0

log4j在有log4j.properties的情况下在控制台提示如下错误:

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 [java.net.URLClassLoader@6a6824be] whereas object of type 
log4j:ERROR "org.apache.log4j.ConsoleAppender" was loaded by [ParallelWebappClassLoader
  context: j2eeHW0602_war_exploded
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@6a6824be
].
log4j: ERROR Could not instantiate appender named "stdout".

log4j.properties文件如下:

log4j.rootLogger=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n

log4j.properties文件存在于resources文件夹下

加载中
0
青菜豆腐汤11

原因是appender和consoleAppender两个文件的classloader不一致。

你自己的war包,是不是包含了log4j的lib? 建议把它删除,放到tomcat目录的lib文件夹

OSCHINA
登录后可查看更多优质内容
返回顶部
顶部