日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

SprngBoot引用外部jar包和本身日志接口冲突问题解决办法

發(fā)布時間:2023/12/18 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SprngBoot引用外部jar包和本身日志接口冲突问题解决办法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

今天啟動springboot 遇到這個么錯誤

Connected to the target VM, address: ‘127.0.0.1:10568’, transport:
‘socket’ SLF4J: Class path contains multiple SLF4J bindings. SLF4J:
Found binding in
[jar:file:/D:/java/java_workSpace/WeixinKaipiao/lib/baiwang-bopsdk-1.3.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in
[jar:file:/D:/java/apache-maven-3.6.0-bin/apache-maven-3.6.0/respontry/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an
explanation. SLF4J: Actual binding is of type
[org.slf4j.impl.Log4jLoggerFactory] 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:/D:/java/java_workSpace/WeixinKaipiao/lib/baiwang-bopsdk-1.3.0.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:637)
at org.springframework.util.Assert.isInstanceOf(Assert.java:537)

原因

大致看了看也能猜到一二,在類路徑中 Found binding 2次 SLF4J 日志接口。

經(jīng)查官方日志文檔:

SLF4J API is designed to bind with one and only one underlying logging framework at a time. If more than one binding is present on the class path, SLF4J will emit a warning, listing the location of those bindings.When multiple bindings are available on the class path, select one and only one binding you wish to use, and remove the other bindings. For example, if you have both slf4j-simple-1.8.0-beta4.jar and slf4j-nop-1.8.0-beta4.jar on the class path and you wish to use the nop (no-operation) binding, then remove slf4j-simple-1.8.0-beta4.jar from the class path.The list of locations that SLF4J provides in this warning usually provides sufficient information to identify the dependency transitively pulling in an unwanted SLF4J binding into your project. In your project's pom.xml file, exclude this SLF4J binding when declaring the unscrupulous dependency. For example, cassandra-all version 0.8.1 declares both log4j and slf4j-log4j12 as compile-time dependencies. Thus, when you include cassandra-all as a dependency in your project, the cassandra-all declaration will cause both slf4j-log4j12.jar and log4j.jar to be pulled in as dependencies. In case you do not wish to use log4j as the the SLF4J backend, you can instruct Maven to exclude these two artifacts as shown next:<dependencies><dependency><groupId> org.apache.cassandra</groupId><artifactId>cassandra-all</artifactId><version>0.8.1</version><exclusions><exclusion> <groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId></exclusion><exclusion> <groupId>log4j</groupId><artifactId>log4j</artifactId></exclusion></exclusions> </dependency> </dependencies> NOTE The warning emitted by SLF4J is just that, a warning. Even when multiple bindings are present, SLF4J will pick one logging framework/implementation and bind with it. The way SLF4J picks a binding is determined by the JVM and for all practical purposes should be considered random. As of version 1.6.6, SLF4J will name the framework/implementation class it is actually bound to.Embedded components such as libraries or frameworks should not declare a dependency on any SLF4J binding but only depend on slf4j-api. When a library declares a compile-time dependency on a SLF4J binding, it imposes that binding on the end-user, thus negating SLF4J's purpose. When you come across an embedded component declaring a compile-time dependency on any SLF4J binding, please take the time to contact the authors of said component/library and kindly ask them to mend their ways.

給出引用依賴,但是我的引用外部jar 和 springboot本身的slf4j 沖突,這個依賴不能解決我的問題。

所以最后將jar或者 springboot本身的slf4j 去除一個,可以解決。

jar 又得重新編譯打包,麻煩,果斷去除sb本身的slf4j 。

解決辦法:

starter-web 啟動依賴中剔除slf4j

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><exclusions><exclusion><groupId>ch.qos.logback</groupId><artifactId>logback-classic</artifactId></exclusion></exclusions>

或者添加依賴

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-configuration-processor</artifactId><optional>true</optional></dependency>

啟動會以jar的默認日志級別啟動。

然后成功啟動!

SLF4J 文檔 : http://www.slf4j.org/codes.html#multiple_bindings

建議將springboot 本身日志logback 日志剔除,修改為和倒入外部jar同步的log日志

總結(jié)

以上是生活随笔為你收集整理的SprngBoot引用外部jar包和本身日志接口冲突问题解决办法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。