Java Spring Boot - NoClassDefFoundError: ch/qos/logback/classic/Level

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47894774/
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-12 02:43:23  来源:igfitidea点击:

Spring Boot - NoClassDefFoundError: ch/qos/logback/classic/Level

javaspringeclipsemaven

提问by tenticon

I created a vanilla Spring Boot App (1.5.9.RELEASE) but when I Run As -> Spring Boot App(in Eclipse Oxygen) I get

我创建了一个香草 Spring Boot 应用程序(1.5.9.RELEASE)但是当我Run As -> Spring Boot App(在 Eclipse Oxygen 中)我得到

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.NoClassDefFoundError: ch/qos/logback/classic/Level
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.<clinit>(LogbackLoggingSystem.java:66)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at org.springframework.boot.logging.LoggingSystem.get(LoggingSystem.java:170)
    at org.springframework.boot.logging.LoggingSystem.get(LoggingSystem.java:160)
    at org.springframework.boot.logging.LoggingApplicationListener.onApplicationStartingEvent(LoggingApplicationListener.java:229)
    at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:209)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)
    at org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:69)
    at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:48)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:292)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
    at demo.spring.boot.app.CourseApiApp.main(CourseApiApp.java:11)
Caused by: java.lang.ClassNotFoundException: ch.qos.logback.classic.Level
    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)
    ... 19 more

pom.xml

pom.xml

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>demo.spring.boot</groupId>
  <artifactId>boot-demo</artifactId>
  <version>0.0.1-SNAPSHOT</version>

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

  <dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
  </dependencies>

  <properties>
    <java.version>1.8</java.version>
  </properties>

  <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

App

应用程序

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class CourseApiApp {

    public static void main(String[] args) 
    {
        SpringApplication.run(CourseApiApp.class, args);
    }
}

Remark

评论

I also tried mvn clean package-> java -jar target/boot-demo.jarwhich gives me

我也试过mvn clean package->java -jar target/boot-demo.jar这给了我

Failed to instantiate SLF4J LoggerFactory
Reported exception:
java.lang.NoClassDefFoundError: ch/qos/logback/classic/LoggerContext
    at org.slf4j.impl.StaticLoggerBinder.<init>(StaticLoggerBinder.java:59)
    at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:50)
    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.<clinit>(SpringApplication.java:179)
    at demo.spring.boot.app.CourseApiApp.main(CourseApiApp.java:11)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: java.lang.ClassNotFoundException: ch.qos.logback.classic.LoggerContext
    at java.net.URLClassLoader.run(URLClassLoader.java:370)
    at java.net.URLClassLoader.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 19 more
Caused by: java.util.zip.ZipException: invalid stored block lengths
    at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164)
    at org.springframework.boot.loader.jar.ZipInflaterInputStream.read(ZipInflaterInputStream.java:52)
    at sun.misc.Resource.getBytes(Resource.java:124)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:462)
    at java.net.URLClassLoader.access0(URLClassLoader.java:73)
    at java.net.URLClassLoader.run(URLClassLoader.java:368)
    ... 25 more
Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: java.lang.NoClassDefFoundError: ch/qos/logback/classic/LoggerContext
    at org.slf4j.impl.StaticLoggerBinder.<init>(StaticLoggerBinder.java:59)
    at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:50)
    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.<clinit>(SpringApplication.java:179)
    at demo.spring.boot.app.CourseApiApp.main(CourseApiApp.java:11)
    ... 8 more
Caused by: java.lang.ClassNotFoundException: ch.qos.logback.classic.LoggerContext
    at java.net.URLClassLoader.run(URLClassLoader.java:370)
    at java.net.URLClassLoader.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 19 more
Caused by: java.util.zip.ZipException: invalid stored block lengths
    at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164)
    at org.springframework.boot.loader.jar.ZipInflaterInputStream.read(ZipInflaterInputStream.java:52)
    at sun.misc.Resource.getBytes(Resource.java:124)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:462)
    at java.net.URLClassLoader.access0(URLClassLoader.java:73)
    at java.net.URLClassLoader.run(URLClassLoader.java:368)
    ... 25 more

采纳答案by Guy Smorodinsky

Extending Mark Bramnik answer, It does look like you don't have logback, which is pretty weird because spring-boot-starter-webhave a dependency on spring-boot-starter-logging. Just try to add spring-boot-starter-loggingto your POM file

扩展 Mark Bramnik 的回答,看起来你没有 logback,这很奇怪,因为spring-boot-starter-web依赖于spring-boot-starter-logging. 只需尝试添加spring-boot-starter-logging到您的 POM 文件中

回答by Mark Bramnik

It looks like you're trying to use a logback logging implementation but don't have a logback jar in the classpath:

看起来您正在尝试使用 logback 日志记录实现,但类路径中没有 logback jar:

Please try adding something like this (depending on Spring Boot version there can be another actual version of logback dependency)

请尝试添加这样的东西(取决于 Spring Boot 版本,可能会有另一个实际版本的 logback 依赖项)

<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>1.1.11</version>
</dependency>

Then you'll probably want to configure loggers, appenders and so forth. For more information about logging in spring boot read a chapter from official Spring Boot documentation.

然后你可能想要配置记录器、附加器等等。有关登录Spring Boot 的更多信息,请阅读Spring Boot 官方文档中的一章

回答by tenticon

Apparently I had a broken jar in the classpath, after removing everything from .m2 and updating it worked.

显然,在从 .m2 中删除所有内容并更新它后,我的类路径中有一个损坏的 jar。

回答by nslangde

Removing everything from maven repo and updating project in eclipse worked for me.

从 maven repo 中删除所有内容并在 eclipse 中更新项目对我有用。

回答by apoorv kapil

    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-core</artifactId>
        <!-- <version>${logback.version}</version> -->
    </dependency>

Adding this logback explicitly, solved the issue in my case.

明确添加此 logback,解决了我的问题。

回答by Sobin George

This worked for me, though not very intelligent: Deleted the ch folder from within .m2 folder, and did a Run > 'Maven install' from Eclipse.

这对我有用,虽然不是很聪明:从 .m2 文件夹中删除了 ch 文件夹,并从 Eclipse 中执行了 Run > 'Maven install'。

回答by arjun ganta

Deleting ch folder in .m2 directory and update maven project in eclipse project helps me in fixing this issue.

删除 .m2 目录中的 ch 文件夹并更新 eclipse 项目中的 maven 项目有助于我解决这个问题。

回答by sandeep vanama

Spring boot application is expecting logback classic dependency.Since its unable to find the logback-classic jar in classpath its throwing an error Caused by: java.lang.NoClassDefFoundError: ch/qos/logback/classic/turbo/TurboFilter.

Spring boot 应用程序期望 logback 经典依赖项。由于它无法在类路径中找到 logback-classic jar,因此引发错误:java.lang.NoClassDefFoundError: ch/qos/logback/classic/turbo/TurboFilter。

After adding the below dependency application started without any issues.

添加以下依赖项应用程序启动后没有任何问题。

<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>1.1.11</version>
</dependency