Spring Bootプロジェクトを開始すると、slf4jに関連する次のログ例外が発生し、プロジェクトの開始に失敗します。
関連する例外情報は次のとおりです。
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.Log4jLoggerFactory loaded from file:~/.m2/repository/org/slf4j/slf4j-log4j12/1.7.30/slf4j-log4j12-1.7.30.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.Log4jLoggerFactory
at org.springframework.util.Assert.instanceCheckFailed(Assert.java:696)
at org.springframework.util.Assert.isInstanceOf(Assert.java:596)
明らかに、いわゆるweblogic.xmlはプロジェクトで使用されていないので、WEB-INF / weblogic.xmlの構成に関する例外が報告されるのはなぜですか?
主な追加機能は次のとおりです。
LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation……
つまり、Logbackはすでにクラスパスに存在していますが、LoggerFactoryはLogbackに関連するオンラインログの内容ではありません。この時点で、Logback依存関係の競合に注意する必要があります。
この時点で、Mavenの依存関係を確認して問題をトラブルシューティングし、プロジェクトとディレクトリで次のコマンドを実行できます。
mvn dependency:tree
表示結果の内容は以下のとおりです。
[INFO] +- org.springframework.boot:spring-boot-starter:jar:1.3.3.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot:jar:1.3.3.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-autoconfigure:jar:1.3.3.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-logging:jar:1.3.3.RELEASE:compile
[INFO] | | +- ch.qos.logback:logback-classic:jar:1.1.5:compile
[INFO] | | | \- ch.qos.logback:logback-core:jar:1.1.5:compile
[INFO] | | +- org.slf4j:jcl-over-slf4j:jar:1.7.5:compile
[INFO] | | +- org.slf4j:jul-to-slf4j:jar:1.7.5:compile
[INFO] | | \- org.slf4j:log4j-over-slf4j:jar:1.7.5:compile
[INFO] | +- org.springframework:spring-core:jar:4.2.5.RELEASE:compile
[INFO] | \- org.yaml:snakeyaml:jar:1.16:compile
...
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.7.5:compile
[INFO] | \- org.slf4j:slf4j-api:jar:1.7.5:compile
明らかに、同じslf4j-api jarパッケージが複数の場所で参照されていることがわかります。つまり、jarパッケージが競合しています。このとき、依存jarパッケージは除外され、場所は1つしかありません。
springbootのjarパッケージが無効な場合は、次の方法を使用して除外できます。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
他の依存ライブラリのjarパッケージが無効な場合、それらは同じ方法で除外できます。
<dependency>
<groupId>com.github.secbr</groupId>
<artifactId>fastdfs-client-plus</artifactId>
<version>1.1.1-RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
その後、springbootプロジェクトを再起動すると、プロジェクトは正常に開始できます。
元のリンク:「Spring Boot start slf4jがweblogic.xmlログ例外が見つからないことを通知する」
ファインスプリングブート2.xビデオチュートリアル
「Spring Boot 2.xビデオチュートリアルファミリーバケット」、Spring Boot 2.xビデオチュートリアルのブティックで、Spring Boot 2.xビデオチュートリアルの最も完全なセットを作成します。