Java Maven Spring Boot 无法实例化 SLF4J LoggerFactory 报告的异常:

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40138247/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 22:25:59  来源:igfitidea点击:

Maven Spring Boot Failed to instantiate SLF4J LoggerFactory Reported exception:

javamavenspring-bootslf4j

提问by

I am following the tutorial https://spring.io/guides/gs/actuator-service/

我正在关注教程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

无法实例化 SLF4J LoggerFactory 报告的异常: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) 在 org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132) 在 org.apache.commons.logging.LogFactory.getLog(LogFactory.java:273) 在 org .springframework.boot.SpringApplication.(SpringApplication.java:189) at hello.HelloWorldConfiguration.main(HelloWorldConfiguration.java:11) 引起: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 更多线程“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) 在 org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357) 在 org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:155) 在 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) 引起: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更多的(SpringApplication.java:189) at hello.HelloWorldConfiguration.main(HelloWorldConfiguration.java:11) 由:java.lang.ClassNotFoundException: ch.qos.logback.core.joran.spi.JoranException at java.net.URLClassLoader.findClass (URLClassLoader.java:381) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:424) 在 sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) 在 java.lang.ClassLoader.loadClass(ClassLoader. java:357) ... 9 更多(SpringApplication.java:189) at hello.HelloWorldConfiguration.main(HelloWorldConfiguration.java:11) 由:java.lang.ClassNotFoundException: ch.qos.logback.core.joran.spi.JoranException at java.net.URLClassLoader.findClass (URLClassLoader.java:381) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:424) 在 sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) 在 java.lang.ClassLoader.loadClass(ClassLoader. java:357) ... 9 更多loadClass(Launcher.java:331) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 9 更多loadClass(Launcher.java:331) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 9 更多

My pom file looks like this:

我的 pom 文件如下所示:

<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 thisbut nothing seems to work.

我不知道如何解决这个问题。我尝试清理和重建,甚至重新导入。我看着像类似的问题但似乎没有任何工作。

The only way I got the program to run was by changing the parent pom to version 1.3.1.RELEASEBut I do not want to use this version and want to use 1.4.1.RELEASE

我让程序运行的唯一方法是将父 pom 更改为 version1.3.1.RELEASE但是我不想使用这个版本并且想使用1.4.1.RELEASE

Any help would be greatly appreciated.

任何帮助将不胜感激。

Here is mvn dependency:tree

这是 mvn 依赖项:树

[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.Hymanson.core:Hymanson-databind:jar:2.8.3:compile
[INFO] |  |  +- com.fasterxml.Hymanson.core:Hymanson-annotations:jar:2.8.3:compile

[INFO] |  |  \- com.fasterxml.Hymanson.core:Hymanson-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_bindingsfor 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

SLF4J:类路径包含多个 SLF4J 绑定。SLF4J:在 [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:在 [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:见http://www.slf4j.org/codes.html#multiple_bindings为解释。无法实例化 SLF4J LoggerFactory 报告异常: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) 在 org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132) 在 org.apache.commons.logging.LogFactory.getLog(LogFactory.java:273) 在 org .springframework.boot.SpringApplication.(SpringApplication.java:189) 在 hello.HelloWorldConfiguration.main(HelloWorldConfiguration.java:

回答by Jay

You need to find log4j and add in your classpath.

您需要找到 log4j 并添加到您的类路径中。

回答by Marcelo Ferreira

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

类路径包含多个 SLF4J 绑定。SLF4J:发现绑定

make a test if use IDE Eclipse

测试是否使用 IDE Eclipse

short cut key: Shift+Ctrl+T

快捷键: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

那个例子,改变你的上下文

回答by Adi

Below actions worked for me

以下操作对我有用

  1. Run mvn dependency:purge-local-repositoryto remove all dependencies and force a re-download.
  2. Then do a mvn clean verify
  1. 运行mvn dependency:purge-local-repository以删除所有依赖项并强制重新下载。
  2. 然后做一个 mvn clean verify

回答by amir110

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 thiserror occurred.

如果发生错误,您只需使用 logback-classic 版本。

回答by InvincibleCoder

The issue does not exists with version 1.3.5. I changed my version to

版本 1.3.5 不存在此问题。我把我的版本改成

<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 !!

有用 !!

回答by bourne

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.

可能是版本问题,我把springboot的版本从2.0.0.RELEASE改成1.5.4.RELEASE,异常消失了。

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.4.RELEASE</version>
</parent>

回答by Brameshwar Gupta

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>`