错误提示
SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found
binding in
[jar:file:/Users/ulricqin/Documents/workspace/uic/web/WEB-INF/lib/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in
[jar:file:/Users/ulricqin/Documents/workspace/uic/web/WEB-INF/lib/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an
explanation.
问题原因
jar包冲突了,slf4j就是所谓的门面模式,提供了一个接口,自己不去实现,让其他日志jar包去实现这个接口。logback、log4j什么的,都有实现这个接口,但运行的时候,必须保证只能有一个接口实现类,如果有两个或以上,就抛上面那个异常了。做下依赖排除就行了,有的时候是其他包里面引进了日志包,不是你自己引进的
如何解决
鉴于大多数模块,都有实现这个接口,那么要做的就是,保证只有一个实现就可以了。其他的排除掉就可以了,对于maven,只需要在依赖中加入exclusions就可以了
更新排除代码配置
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
</exclusion>