类路径包含多个SLF4J绑定spring引导排除问题
我试图在我的springboot项目中包含log4j2,但是我得到了以下错误类路径包含多个SLF4J绑定spring引导排除问题,spring,spring-boot,logging,gradle,log4j2,Spring,Spring Boot,Logging,Gradle,Log4j2,我试图在我的springboot项目中包含log4j2,但是我得到了以下错误 SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/Users/mn/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-slf4j-impl/2.10.0/8e4e0a30736175e31c7f714d95032c1
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/mn/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-slf4j-impl/2.10.0/8e4e0a30736175e31c7f714d95032c1734cfbdea/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/mn/.gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.2.3/7c4f3c474fb2c041d8028740440937705ebb473a/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
我的gradle文件如下所示:
dependencies {
compile('org.springframework.boot:spring-boot-starter') {
exclude module:'spring-boot-starter-logging'
}
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-log4j2')
compile('org.springframework:spring-oxm')
compile('org.codehaus.castor:castor-xml:1.3.3')
compile('org.apache.commons:commons-collections4:4.1')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.security:spring-security-test')
}
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
我很确定SpringBootStarter就是实现日志的那个,这就是为什么我试图排除它,但它不起作用。我排除它是错误的还是错误的?修复了这个问题。这是因为spring boot starter web和spring boot starter security都使用了standart日志,所以必须将其从所有日志中排除
configurations {
//eliminates logback
all*.exclude group: 'ch.qos.logback'
//eliminates StackOverflowError
all*.exclude group: 'org.apache.logging.log4j', module: 'log4j-to-slf4j'
}
来自spring boot starter的多个类使用spring boot starter日志记录
- 在我的例子中,
springbootstarterjdbc
和springbootstarterweb
您应该使用
标记排除依赖关系,如下所示:
dependencies {
compile('org.springframework.boot:spring-boot-starter') {
exclude module:'spring-boot-starter-logging'
}
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-log4j2')
compile('org.springframework:spring-oxm')
compile('org.codehaus.castor:castor-xml:1.3.3')
compile('org.apache.commons:commons-collections4:4.1')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.security:spring-security-test')
}
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
org.springframework.boot
SpringBootStarterWeb
org.springframework.boot
spring启动程序日志记录
对于初学者,停止混合使用Spring启动版本、Spring版本和Spring安全版本。Spring Boot 1.5不适用于Spring Security 5(从Spring Security test
中删除版本这也适用于Spring Boot start test
、Spring-Boot-starter-log4j2`和Spring oxm
依赖项)。您想让我从所有这些版本中删除版本,还是只删除Spring Security test?所有这些,Spring Boot将为您管理这些版本。您当前正在混合至少2个spring版本(可能还有3个)以及不同的依赖项和托管依赖项。已编辑gradle文件。现在,我在哪里声明要使用的实际版本呢?您不需要像之前所说的那样,通过SpringBoot插件,SpringBoot为您管理这个版本。