今天启动项目时提示失败,失败日志如下:
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.apache.logging.slf4j.Log4jLoggerFactory loaded from file:/C:/Users/86186/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.10.0/log4j-slf4j-impl-2.10.0.jar). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.apache.logging.slf4j.Log4jLoggerFactory
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.ooomap.user.OooMapUserApplication.main(OooMapUserApplication.java:27)
Disconnected from the target VM, address: '127.0.0.1:59593', transport: 'socket'
1.分析日志
从日志报错的信息可以看出是因为class path中引入了Logback,但在项目中使用的LoggerFactory 并不是logback中的,导致日志加载失败
2.查找项目中的依赖
使用idea查找依赖
按住ctrl+鼠标滚轮将其放大,然后按ctrl+f 查找logback
选中箭头指向logback的线条,找到依赖logback的jar,从图中可以看出是play-core中依赖了logback,然后依次往上查找,最后发现是阿里云的大于中的依赖了loback
3.排除依赖
使用exclusion将其依赖的logback移除
<dependency>
<groupId>com.airlenet</groupId>
<artifactId>play-aliyun-dysms</artifactId>
<version>${play-aliyun-dysms.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
4.启动项目
心得:使用google和baidu搜索的结果很多都不是自己想要的答案,
每个人出现错误的环境也不同,只有自己通过分析查找到问题的根本原因,才能对自己有所提升。很多时候我们一出现问题连看不都不看就直接去搜索答案,这就会形成一种依赖,当没有这些搜索工具的时候,我们就无法去分析和解决问题。