6

I use gradle and latest.release everywhere to be promiscuous, however, recently my Spring boot application stopped running from command line. When I run gradle clean bootRun I get...

Exception in thread "main" java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.impl.Log4jLoggerFactory loaded from file:/.../.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-log4j12/1.7.25/110cefe2df103412849d72ef7a67e4e91e4266b4/slf4j-log4j12-1.7.25.jar). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.impl.Log4jLoggerFactory

Per this post I tried...

configurations.all {
    exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
    exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
    exclude group: 'org.springframework.boot', module: 'logback-classic'
    exclude group: "org.slf4j"
}

and that silences the Logback error but spring won't start and fails with no error.

Caused by: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

What am I missing?

Jackie
  • 21,969
  • 32
  • 147
  • 289

3 Answers3

5

I had this and fixed it by excluding spring-boot-starter-logging and logback-classic and adding spring log4j2 implementation in gradle.build

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

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-log4j2:2.2.6.RELEASE'
rupweb
  • 3,052
  • 1
  • 30
  • 57
  • 1
    I have faced the exact same issue and have tried the above steps. But I see the following error : ERROR 23048 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter *************************** APPLICATION FAILED TO START *************************** Description: An attempt was made to call a method that does not exist. The attempt was made from the following location: org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition.(AnnotatedGenericBeanDefinition.java:58) – Soumya C May 20 '21 at 10:24
  • sounds like you need to check the dependency version numbers in your `gradle.build` – rupweb May 20 '21 at 10:26
  • Can you be a little more specific? I have a lot of dependencies, so which version should I check? I am new to Gradle and Spring, so do not have a great idea – Soumya C May 20 '21 at 10:35
  • "An attempt was made to call a method that does not exist" is the clue. That there is some version conflict. Are you using 2.2.6.RELEASE for log4j2 or another version? – rupweb May 20 '21 at 10:49
  • Yes I am using the exact same version you mentioned above. My Spring cloud context is using 2.2.0.RELEASE and Spring framework security is using 1.0.0.RELEASE. Lombok is 1.18.20 – Soumya C May 20 '21 at 11:35
  • I am afraid you will have to play around with the versions until you fix the "An attempt was made to call a method that does not exist". I suggest look at [MVN repository](https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-log4j2) for each of your dependencies and update them all to the latest version. For example now use log4j2 2.4.5 version. Then work backwards if there are still conflicts. Good luck! – rupweb May 20 '21 at 11:51
  • Thanks, will check accordingly – Soumya C May 20 '21 at 12:00
0

Needed to remove.. compile 'org.apache.spark:spark-sql_2.11:latest.release'

Haven't figured out through why.

Jackie
  • 21,969
  • 32
  • 147
  • 289
0

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

You can also try module replacement to replace the LogBack to Log4j or Log4j2

Praj
  • 451
  • 2
  • 5