Chevy
Chevy

Reputation: 23

SLF4J AND LOG4J binding exception in spring boot app with ignite dependency

Hi,

Below exception is thrown when I include ignite dependency with my spring boot app. Even though reason seems obvious that 2 jars are in deadlock here, can you suggest me how can I fix this. I am not adding any of these jars directly and these are included automatically with other dependencies.

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

Exception:

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.

Upvotes: 1

Views: 1187

Answers (1)

Sundararaj Govindasamy
Sundararaj Govindasamy

Reputation: 8495

You have to exclude conflicting dependencies, like below.

Refer official documentation for more info.

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

Example from the official documentation:

enter image description here

Upvotes: 2

Related Questions