弹簧启动应用程序中的SLF4J和LOG4J绑定异常具有点燃依赖性

时间:2016-10-21 19:09:36

标签: spring-boot log4j slf4j ignite

  

嗨,

     

当我使用spring boot app包含点燃依赖项时,抛出异常。虽然原因似乎很明显,这里有2个罐子陷入僵局,你能否告诉我如何解决这个问题。我没有直接添加任何这些罐子,这些罐子会自动包含在其他依赖项中。

的build.gradle

buildscript {
    repositories {
        mavenCentral()
        maven { url "http://repo.spring.io/libs-snapshot" } 
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.1.RELEASE")
        classpath 'mysql:mysql-connector-java:5.1.34' 
    }
}

    // Apply the java plugin to add support for Java
    apply plugin: 'java'
    apply plugin: 'eclipse'
    apply plugin: 'idea'
    apply plugin: 'spring-boot'

    jar {
        baseName = 'gs-spring-boot'
        version =  '0.1.0'
    }

    // In this section you declare where to find the dependencies of your project
    repositories {
        // Use 'jcenter' for resolving your dependencies.
        // You can declare any Maven/Ivy/file repository here.
        mavenCentral()
        maven { url "http://repo.spring.io/libs-snapshot" } 
        jcenter()
    }

    sourceCompatibility = 1.8
    targetCompatibility = 1.8

// In this section you declare the dependencies for your production and test code
dependencies {
    compile("org.springframework.boot:spring-boot-starter-web") 
    compile("org.springframework.boot:spring-boot-starter-jdbc")
    compile("org.springframework.boot:spring-boot-starter-data-jpa") 
    compile("mysql:mysql-connector-java:5.1.34")

    // Ignite dependencies
    compile group: 'org.apache.ignite', name: 'ignite-core', version: '1.6.0'
    compile group: 'org.apache.ignite', name: 'ignite-spring', version: '1.6.0'
    compile group: 'org.apache.ignite', name: 'ignite-indexing', version: '1.6.0'
    compile group: 'org.apache.ignite', name: 'ignite-rest-http', version: '1.6.0'

    testCompile 'junit:junit:4.12'
}

例外:

SLF4J: Class path contains multiple SLF4J bindings. 
SLF4J: Found binding in [jar:file:/usr/local/Cellar/gradle/2.13/caches/modules-2/files-2.1/org.slf4j/slf4j-log4j12/1.7.21/7238b064d1aba20da2ac03217d700d91e02460fa/slf4j-log4j12-1.7.21.jar!/org/slf4j/impl/StaticLoggerBinder.class] 
SLF4J: Found binding in [jar:file:/usr/local/Cellar/gradle/2.13/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.1.7/9865cf6994f9ff13fce0bf93f2054ef6c65bb462/logback-classic-1.1.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]  
SLF4J: Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path, preempting StackOverflowError.  
Exception in thread "main" java.lang.ExceptionInInitializerError 
        at org.slf4j.impl.StaticLoggerBinder.<init>(StaticLoggerBinder.java:72) 
        at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:45) 
        at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150) 
        at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124) 
        at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412) 
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357) 
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383) 
        at com.boot.App.<clinit>(App.java:42) 
Caused by: java.lang.IllegalStateException: Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path, preempting StackOverflowError.

1 个答案:

答案 0 :(得分:2)

您必须排除冲突的依赖关系,如下所示。

有关详细信息,请参阅官方documentation

exclude group: 'org.slf4j', module: 'slf4j-log4j12'

官方文档中的示例:

enter image description here