spring - 类路径包含多个SLF4J绑定(bind)spring boot排除问题

标签 spring spring-boot logging gradle log4j2

我试图将 log4j2 包含在我的 springboot 项目中,但出现以下错误。

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')                  
} 

我很确定 Spring-boot-starter 是实现日志记录的那个,这就是为什么我尝试排除它,但它不起作用。我排除它是错误的还是错误的事情?

最佳答案

我用过这个

configurations {
    //eliminates logback
    all*.exclude group: 'ch.qos.logback'

    //eliminates StackOverflowError
    all*.exclude group: 'org.apache.logging.log4j', module: 'log4j-to-slf4j'
}

关于spring - 类路径包含多个SLF4J绑定(bind)spring boot排除问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48746059/

相关文章:

java - 当从 @Transactional 方法(Spring boot)返回对象时,为什么 Hibernate 没有完全解析我的对象?

java - JDBC API 用于修剪字符串长度以匹配数据库列规范

spring - 使用功能区进行负载平衡

java - 考虑在您的配置中定义类型为 'com.example.conexion.repository.ClienteRepository' 的 bean

java - 用于 Spring-Data-JPA 注释的 setMaxResults?

spring - 如何使用 Spring Boot 应用程序实现 JPA 事务?

javascript - @sentry/node 集成将 Bunyan 日志调用包装为面包屑

hadoop - 为什么即使启用了日志记录,我的 yarn 应用程序也没有日志?

php - 生产中的 Symfony 日志记录忽略日志级别

java - 如何使用 Spring MockMVC 将 JSON 编码为请求参数