spring-boot - 当我尝试创建新的 Spring Boot 项目时,无法实例化 SLF4J LoggerFactory

标签 spring-boot

我是使用 Spring 开发 Web 项目的新手。我正在尝试创建一个新的 Spring Boot 项目,但无法运行我正在创建的应用程序。 我已经尝试了与该主题相关的所有建议答案,但没有任何运气。 这是我的错误:

 Failed to instantiate SLF4J LoggerFactory
   Reported exception:
java.lang.NoClassDefFoundError: ch/qos/logback/core/spi/LifeCycle
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.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 sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    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 com.example.demo.DemoApplication.main(DemoApplication.java:10)
Caused by: java.lang.ClassNotFoundException: ch.qos.logback.core.spi.LifeCycle
    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)
    ... 23 more
Exception in thread "main" java.lang.NoClassDefFoundError: ch/qos/logback/core/spi/LifeCycle
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.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 sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    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 com.example.demo.DemoApplication.main(DemoApplication.java:10)
Caused by: java.lang.ClassNotFoundException: ch.qos.logback.core.spi.LifeCycle
    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)
    ... 23 more

Process finished with exit code 1

有什么想法吗?谢谢。

最佳答案

将以下库添加到pom.xml

   <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>

也试试这个:

mvn dependency:purge-local-repository

并进行maven更新

关于spring-boot - 当我尝试创建新的 Spring Boot 项目时,无法实例化 SLF4J LoggerFactory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47203141/

相关文章:

java - 使用我的自定义外部登录与 spring boot oauth2 (授权授予类型)?

java - Spring Cloud Gateway 不适用于 @Bean DiscoveryClientRouteDefinitionLocator

spring - 如何使用 spring boot 在 H2 控制台中设置默认的 JDBC URL 值

java - Camunda 在 Spring Boot 应用程序上禁用 DbHistoryEventHandler

java - Spring 批处理中的重写 Bean 问题

java - Spring 和 AngularJS 位于同一应用程序的不同项目中

java - 如何在Spring Boot中的application.properties中指定外部属性文件?

spring-boot - 微服务先返回响应再处理请求

java - Spring Boot - 从 application.yml 注入(inject)静态映射

java - Thymeleaf,如何用一串文本做一个新段落