项目中引用solr、lucene导致log4j日志无法正常输出,有可能是因为solr引用log4j和项目引用的log4j不一致导致的。比如“log4j-slf4j-impl”和“slf4j-log4j12”同时被引用,tomcat启动是就会报多绑定冲突
SLF4J: Found binding in [jar:***/WEB-INF/lib/log4j-slf4j-impl-2.14.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:***/WEB-INF/lib/slf4j-log4j12-1.7.30.jar!/org/slf4j/impl/StaticLoggerBinder.class]
解决方法很简单:将solr的log4j排除即可
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-core</artifactId>
<version>8.11.0</version>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>