解决报错:Caused by: java.lang.IllegalStateException: Detected both log4j-over-slf4j.jar AND
错误现象
Caused by: java.lang.IllegalStateException: Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path, preempting StackOverflowError. See also http://www.slf4j.org/codes.html\#log4jDelegationLoop for more details.
at org.slf4j.impl.Log4jLoggerFactory.
… 24 more
原因
- SLF4JAPI被设计成一次只绑定一个底层日志框架。如果在类路径上存在不止一个绑定,则SLF4J将发出警告,列出这些绑定的位置。
- SLF4J在这个警告中提供的位置列表通常提供足够的信息来标识在不必要的SLF4J绑定中向项目中过渡的依赖性。在项目的POM.XML文件中,在声明不法依赖时排除此SLF4J绑定。
解决方法
以我为例,我是在pom中引入 fastdfs-client-java 依赖时出现这个错误,所以只要在该依赖中屏蔽slf4j-log4j12依赖即可:
<!--FastDFS-Client-Java-->
<dependency>
<groupId>org.csource</groupId>
<artifactId>fastdfs-client-java</artifactId>
<version>1.27-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
官方示例
cassandra-all版本0.8-1声明两者Log4J和slf4j-log4j12作为编译时依赖项。因此,当你包括cassandra-all作为项目中的依赖项,cassandra-all声明将导致两者slf4j-log4j12.jar和log4j.jar作为依赖而被拉进去。如果您不希望使用Log4J作为SLF4J后端,则可以指示Maven排除这两个工件,如下所示:
<dependencies>
<dependency>
<groupId> org.apache.cassandra</groupId>
<artifactId>cassandra-all</artifactId>
<version>0.8.1</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
还没有评论,来说两句吧...