如何修复NoClassDefFoundError: Could not initialize class org.slf4j.MDC
?我在pom.xml
flyway插件中,slf4j
被排除在外,以支持新版本。
[INFO] | \- org.slf4j:slf4j-simple:jar:1.5.6:compile
[INFO] +- org.springframework:spring-beans:jar:4.1.4.RELEASE:compile
[INFO] +- org.springframework:spring-core:jar:4.1.4.RELEASE:compile
[INFO] | \- commons-logging:commons-logging:jar:1.2:compile
[INFO] +- org.springframework:spring-webmvc:jar:4.1.4.RELEASE:compile
[INFO] | +- org.springframework:spring-expression:jar:4.1.4.RELEASE:compile
[INFO] | \- org.springframework:spring-web:jar:4.1.4.RELEASE:compile
[INFO] +- org.springframework:spring-tx:jar:4.1.4.RELEASE:compile
[INFO] +- org.springframework:spring-jdbc:jar:4.1.4.RELEASE:compile
[INFO] +- org.springframework:spring-orm:jar:4.1.4.RELEASE:compile
[INFO] +- org.springframework:spring-context:jar:4.1.4.RELEASE:compile
[INFO] | \- org.springframework:spring-aop:jar:4.1.4.RELEASE:compile
[INFO] | \- aopalliance:aopalliance:jar:1.0:compile
[INFO] +- ch.qos.logback:logback-classic:jar:1.1.2:compile
[INFO] | +- ch.qos.logback:logback-core:jar:1.1.2:compile
[INFO] | \- org.slf4j:slf4j-api:jar:1.7.6:compile
[INFO] +- org.slf4j:jcl-over-slf4j:jar:1.7.10:compile
的pom.xml
<dependency>
<groupId>org.flywaydb.flyway-test-extensions</groupId>
<artifactId>flyway-spring4-test</artifactId>
<version>3.1</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${jcloverslf4j.version}</version>
</dependency>
答案 0 :(得分:1)
org.slf4j:slf4j-simple:jar:1.5.6:compile
org.slf4j:slf4j-api:jar:1.7.6:compile
org.slf4j:jcl-over-slf4j:jar:1.7.10:compile
这些版本需要匹配。他们不匹配。至少,次要版本(1.X中的X)需要匹配。另外,如果您正在使用logback,请摆脱slf4j-simple。只有一个slf4j后端应该在类路径上。