1. 程式人生 > >Springboot2.0啟動報錯:java.lang.NoClassDefFoundError: ch/qos/logback/core/spi/LifeCycle

Springboot2.0啟動報錯:java.lang.NoClassDefFoundError: ch/qos/logback/core/spi/LifeCycle

springboot2.0啟動報錯:

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:335)     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.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:39)     at org.apache.commons.logging.LogFactory$Log4jLog.<init>(LogFactory.java:204)     at org.apache.commons.logging.LogFactory$Log4jDelegate.createLog(LogFactory.java:166)     at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:109)     at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:99)     at org.springframework.boot.SpringApplication.<clinit>(SpringApplication.java:201)     at com.example.demo.HelloMqApplication.main(HelloMqApplication.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:335)     at java.lang.ClassLoader.loadClass(ClassLoader.java:357)     ... 25 more

springcloud整合springboot2.0啟動報錯:

Exception in thread "main" java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.impl.SimpleLoggerFactory loaded from file:/E:/maven/repository/org/slf4j/slf4j-simple/1.7.25/slf4j-simple-1.7.25.jar). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.impl.SimpleLoggerFactory     at org.springframework.util.Assert.instanceCheckFailed(Assert.java:637)     at org.springframework.util.Assert.isInstanceOf(Assert.java:537)     at org.springframework.boot.logging.logback.LogbackLoggingSystem.getLoggerContext(LogbackLoggingSystem.java:274)     at org.springframework.boot.logging.logback.LogbackLoggingSystem.beforeInitialize(LogbackLoggingSystem.java:99)     at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationStartingEvent(LoggingApplicationListener.java:191)     at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:170)     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:127)     at org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:68)     at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:48)     at org.springframework.boot.SpringApplication.run(SpringApplication.java:313)     at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255)     at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243)     at com.lll.EurekaServerApp.main(EurekaServerApp.java:14)

解決:

此錯誤是因為缺少依賴或者maven倉庫的jar包版本過低,所以我們只需要在pom檔案中新增一下依賴重新啟動即可:

        <dependency>             <groupId>ch.qos.logback</groupId>             <artifactId>logback-classic</artifactId>             <version>1.2.3</version>         </dependency>         <dependency>             <groupId>ch.qos.logback</groupId>             <artifactId>logback-core</artifactId>             <version>RELEASE</version>         </dependency>