class path contains multiple SLF4J bindings spring boot exclude issue
Asked Answered
S

4

5

Im trying to include log4j2 in my springboot project, but i get the following error.

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]

My gradle file looks like this:

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

Im pretty sure the Spring-boot-starter is the one implementing the logging, which is why i tried excluding that, but it doesnt work. Am i excluding it wrong, or the wrong thing?

Synchronous answered 12/2, 2018 at 12:2 Comment(8)
For starters stop mixing Spring Boot versions, Spring versions and Spring Security versions. Spring Boot 1.5 doesn't work with Spring Security 5 (remove the version from spring-security-test this also applies to the spring-boot-start-test, spring-boot-starter-log4j2` and spring-oxm dependencies).Olives
Do you want me to remove the versions from all of those, or just spring-security-test?Synchronous
All of those, Spring Boot will manage the versions for you. You are currently mixing at least 2 spring versions (and probably 3) and different dependencies and managed dependencies.Olives
edited the gradle file. Now where do i declare the actual version to use?Synchronous
You don't as stated Spring Boot managed that for you, through the Spring Boot plugin.Olives
I feel like just relying on latest versions all the time, is pretty bad, if changed are made that messes things up? or is it this one? buildscript { ext { springBootVersion = '2.0.0.RC1' }Synchronous
You don't rely on the latest version, the specified Spring Boot version manages the dependency versions. That's what M. Deinum mentioned. So only if you upgrade the Spring Boot version, it will upgrade also the other dependencies.Kylix
Okay cool. So my gradle file looks like this now. I still have the issue though :)Synchronous
S
3

Fixed this. It was cause because both spring-boot-starter-web and spring-boot-starter-security also uses the standart logging, so it had to be excluded from all of them

Synchronous answered 12/2, 2018 at 13:17 Comment(0)
E
4

I used this

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

    //eliminates StackOverflowError
    all*.exclude group: 'org.apache.logging.log4j', module: 'log4j-to-slf4j'
}
Excite answered 18/4, 2019 at 13:4 Comment(0)
S
3

Fixed this. It was cause because both spring-boot-starter-web and spring-boot-starter-security also uses the standart logging, so it had to be excluded from all of them

Synchronous answered 12/2, 2018 at 13:17 Comment(0)
T
2

Multiple classes from spring-boot-starter use spring-boot-starter-logging:

  • In my case both spring-boot-starter-jdbc and spring-boot-starter-web

You should exclude the dependecy using the <exclusion> tag, like this:

<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>
Tubman answered 2/6, 2021 at 21:15 Comment(0)
L
0

also exclude from: spring-boot-starter-test, for checking all dependencies, run:

 mvn dependency:tree -Dverbose

If keycloak error with jboss logging, add config into active profile:

logging:
  provider: org.apache.logging.log4j.LogManager

If meet error below:

java.lang.NoClassDefFoundError: com/lmax/disruptor/SequenceReportingEventHandler

Add dependency:

<dependency>
    <groupId>com.lmax</groupId>
    <artifactId>disruptor</artifactId>
    <version>3.4.2</version>
</dependency>
Linkman answered 22/3, 2023 at 11:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.