75

I think some module in spring-boot-starter-security is conflict with log4j, but I don't know which one.

my gradle dependence is as following:

compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-starter-security"){
    exclude module: "spring-boot-starter-logging"
}

compile "org.apache.logging.log4j:log4j-api"
compile "org.apache.logging.log4j:log4j-core"
compile "org.apache.logging.log4j:log4j-slf4j-impl"
compile('org.apache.poi:poi:3.10.1')
compile('org.apache.poi:poi-ooxml:3.10.1')
testCompile("junit:junit")
1
  • This article helped me to better understand and solve the problem: tedblob.com/…
    – Peter
    Commented Aug 9, 2022 at 11:28

12 Answers 12

70

Same solution for maven:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
    <version>1.5.1.RELEASE</version>
    <exclusions>
        <exclusion>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
        </exclusion>
    </exclusions>
</dependency>
1
  • I came across the same with spring-kaka-test
    – Mark80
    Commented Feb 5 at 9:35
41

The problem for me went on with: Either remove Logback or the competing implementation class org.apache.logging.slf4j.Log4jLoggerFactory loaded from log4j-slf4j-impl-2.12.0.jar

I added

configurations {
    all {
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
        exclude group: 'ch.qos.logback', module: 'logback-classic'
        exclude group: 'org.apache.logging.log4j', module: 'log4j-to-slf4j'
    }
}

to my gradle.build and also refreshed all project dependencies with the latest versions and the problem resolved.

37

i figured out

compile("org.springframework.boot:spring-boot-starter-security"){
    exclude module: "spring-boot-starter-logging"
    exclude module: "logback-classic"
}
compile("org.springframework.boot:spring-boot-starter-thymeleaf"){
    exclude module: "logback-classic"
}
2
  • 1
    also applies to webflux compile(group: 'org.springframework.boot', name: 'spring-boot-starter-webflux', version: '2.2.6.RELEASE') { // exclude modules } Commented Apr 12, 2020 at 21:30
  • ... and also for spring-boot-starter-mail, spring-boot-starter-mongodb, spring-boot-starter-data-jpa, . Phew!
    – potame
    Commented May 30, 2022 at 15:31
17

Using the IDEA "Show Dependencies" or mvn dependency:tree -Dverbose to find all the logback-classic jar file, and exclude them.

3
  • 1
    why talk about maven when the question is about gradle?
    – bharal
    Commented Apr 11, 2023 at 20:50
  • gradle dependencies Commented Jun 14, 2023 at 20:10
  • In my case I searched for all "log" dependencies and exclude slf4j-log4j12. Commented Sep 12, 2023 at 5:43
7

Started seeing this error after including 'it.ozimov:embedded-redis:0.7.3' I had to change

testImplementation 'it.ozimov:embedded-redis:0.7.3'

to

testImplementation ('it.ozimov:embedded-redis:0.7.3') {
    exclude module: 'commons-logging'
    exclude module: 'slf4j-simple'
}

and the issue is resolved.

0
6
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-simple</artifactId>
                </exclusion>
            </exclusions>

For me this was the fix, because OpenAPI Generator was bringing this and it conflicted with SpringsBoot Default. So once I excluded this one, the SpringBootApp started working.

2
  • For gradle, implementation("org.openapitools:openapi-generator:6.0.1"){ exclude(group = "slf4j-simple", module = "slf4j-simple") }
    – razvang
    Commented Sep 21, 2022 at 15:12
  • Thank you, including this tag within the openaiapi dependency fixed it. Commented May 11, 2023 at 22:15
3

For me this problem appeared only during execution of maven-surefire-plugin. Somehow Logback is there on the class path, even if its not added to project dependencies. I added such fix:

<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-surefire-plugin</artifactId>
     <version>${maven-surefire-plugin.version}</version>
     <configuration>
        <systemPropertyVariables>
            <org.springframework.boot.logging.LoggingSystem>
                org.springframework.boot.logging.log4j2.Log4J2LoggingSystem
            </org.springframework.boot.logging.LoggingSystem>
        </systemPropertyVariables>
    </configuration>
</plugin>

You can also use

mvn clean install -Dorg.springframework.boot.logging.LoggingSystem=org.springframework.boot.logging.log4j2.Log4J2LoggingSystem
1
  • 1
    Will do my bit: in my case it was because of a "java-gradle-plugin" in gradle plugins section
    – Defake
    Commented Mar 20, 2020 at 8:01
2

According to this documentation, Spring Boot automatically configures the Log Back library because of the web starter. You should exclude the spring-boot-starter-logging to fix the issue.

To exclude the default LogBack configuration on the gradle project,

configurations {
    all*.exclude module : 'spring-boot-starter-logging'
    all*.exclude module : 'logback-classic'
}
1
  • Thank your for your answer! But you should consider editting it to include a quote of the reference you included. This will make your answer more robust in case the reference you link to disappears.
    – Patrick
    Commented Oct 26, 2021 at 10:40
1

works for me:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <!-- avoid: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. on run with vscode -->
            <exclusion>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-classic</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
0

According to this bug, the bundled and undeletable Kotlin plugin (reminds me the forced inclusion of U2's album with iOS) includes org.gradle.kotlin.kotlin-dsl, which in turn pollutes the classpath with an incompatible logging library (even if disabled).

I solved this by changing the runner from "IntelliJ IDEA" to "Gradle" in preferences:

  • Build, Execution, Deployment
    • Build Tools
      • Gradle
        • Build an run using -> Gradle
        • Run tests using -> Gradle
0

Per @Bohemian 's post:

Removing this fixed it for me:

plugins {
    `kotlin-dsl`
}

Bug reference from @Bohemian

This plugin is recommended to be added to gradle files for the kotlin dsl, but I found that it really isn't needed... syntax highlighting still worked for me afterwards and I didn't see any issues after removing it. In fact it removed the issue mentioned in this thread to remove it.

-3

It should be told that after trying to exclude every logback artifact I found which didn't work for me, I just deleted the maven-folder (/.m2). After another

mvn clean install

everything started fine and the error never appeared again. I by the way removed every Exclusion i did before. Still working

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.