我正在使用boot-starter-parent版本2.0.4.RELEASE将spring应用程序转换为spring-boot。当我使用构建
mvn install,运行顺利,但是当我尝试使用命令mvn spring-boot:run -Dspring.profiles.active=dev
运行该应用程序时,出现此异常:
ClassNotFoundException:org.slf4j.impl.StaticLoggerBinder
这是我pom中的依赖项:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.24</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.3.0-alpha4</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.3.0-alpha4</version>
</dependency>
</dependencies>
我尝试遵循this question的建议,并使用新旧版本的logback(核心和经典)依赖项,并添加了“ slf4j-log4j12”和“ slf4j-simple”,但仍然得到了例外。堆栈跟踪为:
java.lang.NoClassDefFoundError:org / slf4j / impl / StaticLoggerBinder 在org.springframework.boot.logging.logback.LogbackLoggingSystem.getLoggerContext(LogbackLoggingSystem.java:285) 在org.springframework.boot.logging.logback.LogbackLoggingSystem.beforeInitialize上(LogbackLoggingSystem.java:102) 在org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationStartingEvent上(LoggingApplicationListener.java:191) 在org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:170) 在org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167) 在org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) 在org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122) 在org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:68) 在org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:48) 在org.springframework.boot.SpringApplication.run(SpringApplication.java:316) 在org.springframework.boot.SpringApplication.run(SpringApplication.java:1258) 在org.springframework.boot.SpringApplication.run(SpringApplication.java:1246) 在com.hbo.esp.MyApplication.main(MyApplication.java:17) 在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)
答案 0 :(得分:0)
尝试如下更改每个依赖项的版本。
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<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>1.2.3</version>
</dependency>
希望这会有所帮助。