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:498)
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.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 jar:file:/data/app/App.jar!/BOOT-INF/lib/log4j-slf4j-impl-2.11.2.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:655)
at org.springframework.util.Assert.isInstanceOf(Assert.java:555)
at org.springframework.boot.logging.logback.LogbackLoggingSystem.getLoggerContext(LogbackLoggingSystem.java:286)
at org.springframework.boot.logging.logback.LogbackLoggingSystem.beforeInitialize(LogbackLoggingSystem.java:102)
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationStartingEvent(LoggingApplicationListener.java:219)
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:198)
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:69)
at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:48)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:302)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
at
就是说Logback已经在classpath中存在,但LoggerFactory并不是Logback的相关日志上线文内容。此时就应该意识到有Logback依赖冲突。
此时,可用过查看maven依赖来排查问题,在项目跟目录执行如下命令:
mvn dependency:tree
展示结果内容如下:
[INFO] | +- org.springframework.boot:spring-boot-starter-data-redis:jar:2.1.5.RELEASE:compile
[INFO] | \- org.redisson:redisson:jar:3.13.1:compile
[INFO] | +- io.netty:netty-common:jar:4.1.36.Final:compile
[INFO] | +- io.netty:netty-codec:jar:4.1.36.Final:compile
[INFO] | +- io.netty:netty-buffer:jar:4.1.36.Final:compile
[INFO] | +- io.netty:netty-transport:jar:4.1.36.Final:compile
[INFO] | | \- io.netty:netty-resolver:jar:4.1.36.Final:compile
[INFO] | +- io.netty:netty-resolver-dns:jar:4.1.36.Final:compile
[INFO] | | \- io.netty:netty-codec-dns:jar:4.1.36.Final:compile
[INFO] | +- io.netty:netty-handler:jar:4.1.36.Final:compile
[INFO] | +- javax.cache:cache-api:jar:1.1.0:compile
[INFO] | +- io.projectreactor:reactor-core:jar:3.2.9.RELEASE:compile
[INFO] | | \- org.reactivestreams:reactive-streams:jar:1.0.2:compile
[INFO] | +- io.reactivex.rxjava2:rxjava:jar:2.2.8:compile
[INFO] | +- org.jboss.marshalling:jboss-marshalling-river:jar:2.0.9.Final:compile
[INFO] | | \- org.jboss.marshalling:jboss-marshalling:jar:2.0.9.Final:compile
[INFO] | +- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.9.8:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-core:jar:2.9.8:compile
[INFO] | \- org.jodd:jodd-bean:jar:5.0.13:compile
[INFO] | \- org.jodd:jodd-core:jar:5.0.13:compile
[INFO] +- org.redisson:redisson-spring-data-21:jar:3.13.1:compile
[INFO] | \- org.springframework.data:spring-data-redis:jar:2.1.8.RELEASE:compile
[INFO] | +- org.springframework.data:spring-data-keyvalue:jar:2.1.8.RELEASE:compile
[INFO] | | \- org.springframework.data:spring-data-commons:jar:2.1.8.RELEASE:compile
[INFO] | \- org.springframework:spring-oxm:jar:5.1.7.RELEASE:compile
[INFO] +- com.github.pagehelper:pagehelper-spring-boot-starter:jar:1.2.3:compile
[INFO] | +- org.mybatis.spring.boot:mybatis-spring-boot-starter:jar:1.3.1:compile
[INFO] | | \- org.mybatis.spring.boot:mybatis-spring-boot-autoconfigure:jar:1.3.1:compile
[INFO] | +- com.github.pagehelper:pagehelper-spring-boot-autoconfigure:jar:1.2.3:compile
[INFO] | \- com.github.pagehelper:pagehelper:jar:5.1.2:compile
[INFO] \- com.alibaba.boot:nacos-config-spring-boot-starter:jar:0.2.1:compile
[INFO] +- com.alibaba.nacos:nacos-spring-context:jar:0.2.2-RC1:compile
[INFO] | +- com.alibaba.nacos:nacos-client:jar:0.2.1-RC1:compile
[INFO] | | +- com.alibaba.nacos:nacos-common:jar:0.2.1-RC1:compile
[INFO] | | +- com.alibaba.nacos:nacos-api:jar:0.2.1-RC1:compile
[INFO] | | +- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO] | | +- ch.qos.logback:logback-core:jar:1.2.3:compile
[INFO] | | \- org.codehaus.jackson:jackson-mapper-lgpl:jar:1.9.6:compile
[INFO] | | \- org.codehaus.jackson:jackson-core-lgpl:jar:1.9.6:compile
[INFO] | \- com.alibaba.spring:spring-context-support:jar:1.0.1:compile
[INFO] +- com.alibaba.boot:nacos-config-spring-boot-autoconfigure:jar:0.2.1:compile
[INFO] \- com.alibaba.boot:nacos-spring-boot-base:jar:0.2.1:compile
很显然,可以看出多处引用了同样的nacos的jar包。也就是jar包冲突了,此时将依赖的jar包排除掉,只有一处即可。logback和log4j冲突
如果是springboot中的jar包无效可使用如下方式排除:
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-config-spring-boot-starter</artifactId>
<version>0.2.1</version>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
</exclusion>
</exclusions>
</dependency>