2

mvn clean install - builds successfully.

java -jar - app runs successfully.

mvn spring-boot:run - throws an error:

Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path, preempting StackOverflowError. See also http://www.slf4j.org/codes.html#log4jDelegationLoop for more details.

[INFO] Building Application 3.1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:2.1.1.RELEASE:run (default-cli) > test-compile @ service-app >>>
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ service-app ---`enter code here`
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 5 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ service-app ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ service-app ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\name\workspace\project\service-app\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ service-app ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] <<< spring-boot-maven-plugin:2.1.1.RELEASE:run (default-cli) < test-compile @ service-app <<<
[INFO]
[INFO]
[INFO] --- spring-boot-maven-plugin:2.1.1.RELEASE:run (default-cli) @ service-app ---
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/name/.m2/repository/org/slf4j/slf4j-log4j12/1.7.25/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/name/.m2/repository/ch/qos/logback/logback-classic/1.1.11/logback-classic-1.1.11.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path, preempting StackOverflowError.
SLF4J: See also http://www.slf4j.org/codes.html#log4jDelegationLoop for more details.
[WARNING]
java.lang.reflect.InvocationTargetException

What is mvn spring-boot:run doing differently?

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.1.1.RELEASE:run (default-cli) on project service-app: An exception occurred while running. null: InvocationTargetException: ExceptionInInitializerError: Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path, preempting StackOverflowError. See also http://www.slf4j.org/codes.html#log4jDelegationLoop for more details. -> [Help 1]

xpagesbeast
  • 776
  • 1
  • 10
  • 21
  • Possible duplicate of https://stackoverflow.com/questions/20117720/detected-both-log4j-over-slf4j-jar-and-slf4j-log4j12-jar-on-the-class-path-pree – wdc Dec 18 '18 at 21:27

2 Answers2

1

Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path, preempting StackOverflowError. See also http://www.slf4j.org/codes.html#log4jDelegationLoop for more details.

You are seeing this because you have multiple implementations of SLF4J Logger in your classpath. You'll have to clean your POM file and keep only one implementation.

You can try excluding the conflicting dependencies,

<exclusions>
  <exclusion> 
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
  </exclusion>
  <exclusion> 
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
  </exclusion>
</exclusions> 
user2004685
  • 9,548
  • 5
  • 37
  • 54
0

In you application you have 2 types of loggers.

1 SLF4J (only an abstraction, no actual logging done by this, so you can switch to different implementations)

2 Log4j1 (this is an implementation , actual logging is done by this )

What happens in your application is

slf4j-log4j12.jar - this jar will route any call made to slf4j loggers (org.slf4j.Logger) into log4j1.

log4j-over-slf4j.jar - this jar will route any call made to log4j loggers (org.apache.log4j.Logger) into slf4j.(this jar normally use when your application is coded with log4j loggers and you want to redirect all those logging calls to SLF4J, so you can change the logging framework to SLF4J without any code change).

when you use both of there jars in the classpath, it circulates logging events between slf4j --> log4j and log4j --> slf4j, that is why an stack overflow exception is occurring.

Depend on your requirement whether you want to use slf4j, or log4j, or log4j-over-slf4j, or slf4j with log4j, you need to select the correct dependencies available in the class path. For your problem you need to exclude slf4j-log4j12.jar or log4j-over-slf4j.jar from your classpath.

Dushmantha
  • 2,911
  • 1
  • 14
  • 21