问题
I am following the tutorial https://spring.io/guides/gs/actuator-service/
And when I try to run the App I get:
Failed to instantiate SLF4J LoggerFactory Reported exception: java.lang.NoClassDefFoundError: ch/qos/logback/core/joran/spi/JoranException 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.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:155) at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132) at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:273) at org.springframework.boot.SpringApplication.(SpringApplication.java:189) at hello.HelloWorldConfiguration.main(HelloWorldConfiguration.java:11) Caused by: java.lang.ClassNotFoundException: ch.qos.logback.core.joran.spi.JoranException at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 9 more Exception in thread "main" java.lang.NoClassDefFoundError: ch/qos/logback/core/joran/spi/JoranException 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.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:155) at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132) at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:273) at org.springframework.boot.SpringApplication.(SpringApplication.java:189) at hello.HelloWorldConfiguration.main(HelloWorldConfiguration.java:11) Caused by: java.lang.ClassNotFoundException: ch.qos.logback.core.joran.spi.JoranException at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 9 more
My pom file looks like this:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
</parent>
<groupId>sample.api</groupId>
<artifactId>api.test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>api.testMaven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<finalName>api.test</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
And I am at a loss for how to fix this issue. I tried cleaning and rebuilding, even re-importing. I looked at similar questions like this but nothing seems to work.
The only way I got the program to run was by changing the parent pom to version 1.3.1.RELEASE
But I do not want to use this version and want to use 1.4.1.RELEASE
Any help would be greatly appreciated.
Here is mvn dependency:tree
[INFO] --- maven-dependency-plugin:2.10:tree (default-cli) @ api.test ---
[INFO] sample.api:api.test:jar:0.0.1-SNAPSHOT
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.4.1.RELEASE:com
pile
[INFO] | +- org.springframework.boot:spring-boot-starter:jar:1.4.1.RELEASE:comp
ile
[INFO] | | +- org.springframework.boot:spring-boot:jar:1.4.1.RELEASE:compile
[INFO] | | +- org.springframework.boot:spring-boot-autoconfigure:jar:1.4.1.REL
EASE:compile
[INFO] | | +- org.springframework.boot:spring-boot-starter-logging:jar:1.4.1.R
ELEASE:compile
[INFO] | | | +- ch.qos.logback:logback-classic:jar:1.1.7:compile
[INFO] | | | +- org.slf4j:jcl-over-slf4j:jar:1.7.21:compile
[INFO] | | | +- org.slf4j:jul-to-slf4j:jar:1.7.21:compile
[INFO] | | | \- org.slf4j:log4j-over-slf4j:jar:1.7.21:compile
[INFO] | | \- org.yaml:snakeyaml:jar:1.17:runtime
[INFO] | +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.4.1.RELEA
SE:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.5:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.5:compile
[INFO] | | \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.5:compile
[INFO] | +- org.hibernate:hibernate-validator:jar:5.2.4.Final:compile
[INFO] | | +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] | | +- org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile
[INFO] | | \- com.fasterxml:classmate:jar:1.3.1:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-databind:jar:2.8.3:compile
[INFO] | | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.3:compile
[INFO] | | \- com.fasterxml.jackson.core:jackson-core:jar:2.8.3:compile
[INFO] | +- org.springframework:spring-web:jar:4.3.3.RELEASE:compile
[INFO] | | +- org.springframework:spring-aop:jar:4.3.3.RELEASE:compile
[INFO] | | +- org.springframework:spring-beans:jar:4.3.3.RELEASE:compile
[INFO] | | \- org.springframework:spring-context:jar:4.3.3.RELEASE:compile
[INFO] | \- org.springframework:spring-webmvc:jar:4.3.3.RELEASE:compile
[INFO] | \- org.springframework:spring-expression:jar:4.3.3.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-actuator:jar:1.4.1.RELEAS
E:compile
[INFO] | \- org.springframework.boot:spring-boot-actuator:jar:1.4.1.RELEASE:com
pile
[INFO] \- org.springframework.boot:spring-boot-starter-test:jar:1.4.1.RELEASE:te
st
[INFO] +- org.springframework.boot:spring-boot-test:jar:1.4.1.RELEASE:test
[INFO] +- org.springframework.boot:spring-boot-test-autoconfigure:jar:1.4.1.R
ELEASE:test
[INFO] +- com.jayway.jsonpath:json-path:jar:2.2.0:test
[INFO] | +- net.minidev:json-smart:jar:2.2.1:test
[INFO] | | \- net.minidev:accessors-smart:jar:1.1:test
[INFO] | | \- org.ow2.asm:asm:jar:5.0.3:test
[INFO] | \- org.slf4j:slf4j-api:jar:1.7.21:compile
[INFO] +- junit:junit:jar:4.12:test
[INFO] +- org.assertj:assertj-core:jar:2.5.0:test
[INFO] +- org.mockito:mockito-core:jar:1.10.19:test
[INFO] | \- org.objenesis:objenesis:jar:2.1:test
[INFO] +- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] +- org.skyscreamer:jsonassert:jar:1.3.0:test
[INFO] | \- org.json:json:jar:20140107:test
[INFO] +- org.springframework:spring-core:jar:4.3.3.RELEASE:compile
[INFO] \- org.springframework:spring-test:jar:4.3.3.RELEASE:test
[INFO] ------------------------------------------------------------------------
Update
If I add
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.5</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
<scope>runtime</scope>
</dependency>
I get
SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/C:/Users/Josh/.m2/repository/ch/qos/logback/logback-classic/1.1.7/logback-classic-1.1.7.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/C:/Users/Josh/.m2/repository/org/slf4j/slf4j-log4j12/1.7.21/slf4j-log4j12-1.7.21.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. Failed to instantiate SLF4J LoggerFactory Reported exception: java.lang.NoClassDefFoundError: ch/qos/logback/core/joran/spi/JoranException 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.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:155) at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132) at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:273) at org.springframework.boot.SpringApplication.(SpringApplication.java:189) at hello.HelloWorldConfiguration.main(HelloWorldConfiguration.java:11) Caused by: java.lang.ClassNotFoundException: ch.qos.logback.core.joran.spi.JoranException at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 9 more Exception in thread "main" java.lang.NoClassDefFoundError: ch/qos/logback/core/joran/spi/JoranException 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.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:155) at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132) at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:273) at org.springframework.boot.SpringApplication.(SpringApplication.java:189) at hello.HelloWorldConfiguration.main(HelloWorldConfiguration.java:11) Caused by: java.lang.ClassNotFoundException: ch.qos.logback.core.joran.spi.JoranException at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 9 more
回答1:
Below actions worked for me
- Run
mvn dependency:purge-local-repository
to remove all dependencies and force a re-download. - Then do a
mvn clean verify
回答2:
I add this dependency and problem resolved.
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${logback.version}</version>
</dependency>
you just use version of logback-classic if this error occurred.
回答3:
You need to find log4j and add in your classpath.
回答4:
See that message: (you manage dependency duplicate, for dependency transitive, that cause dependency duplicate with differents versions)
Class path contains multiple SLF4J bindings. SLF4J: Found binding in
make a test if use IDE Eclipse
short cut key: Shift+Ctrl+T
that way you see what file has contains this class:
SLF4J: Found binding in [jar:file:
/C:/Users/Josh/.m2/repository/ch/qos/logback/logback-classic/1.1.7/logback-classic-1.1.7.jar!
/org/slf4j/impl/StaticLoggerBinder.class]
[jar:file:/C:/Users/Josh/.m2/repository/org/slf4j/slf4j-log4j12/1.7.21/slf4j-log4j12-1.7.21.jar!
/org/slf4j/impl/StaticLoggerBinder.class]
repeat class in
slf4j-log4j12-1.7.21.jar
logback-classic-1.1.7.jar
find your same dependency and exclusion what don't you need in your project
that way:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.0.0-beta2</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>xml-apis</artifactId>
<groupId>xml-apis</groupId>
</exclusion>
</exclusions>
that one example, change for your context
回答5:
The issue does not exists with version 1.3.5. I changed my version to
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
It works !!
回答6:
It may be a version problem, I change my version of springboot from 2.0.0.RELEASE to 1.5.4.RELEASE, the exception disappeared.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
</parent>
回答7:
We can skip logging dependency and it will work for us.
`<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>`
来源:https://stackoverflow.com/questions/40138247/maven-spring-boot-failed-to-instantiate-slf4j-loggerfactory-reported-exception