SprngBoot引用外部jar包日志和本身日志接口沖突問(wèn)題解決辦法

今天啟動(dòng)springboot 遇到這個(gè)么錯(cuò)誤

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 沖突洒忧,這個(gè)依賴不能解決我的問(wèn)題运授。

所以最后將jar或者 springboot本身的slf4j 去除一個(gè)烤惊,可以解決。

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

解決辦法:

starter-web 啟動(dòng)依賴中剔除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>

啟動(dòng)會(huì)以jar的默認(rèn)日志級(jí)別啟動(dòng)逗宜。

然后成功啟動(dòng)伦泥!

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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市锦溪,隨后出現(xiàn)的幾起案子不脯,更是在濱河造成了極大的恐慌,老刑警劉巖刻诊,帶你破解...
    沈念sama閱讀 211,948評(píng)論 6 492
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件防楷,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡则涯,警方通過(guò)查閱死者的電腦和手機(jī)复局,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,371評(píng)論 3 385
  • 文/潘曉璐 我一進(jìn)店門冲簿,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人亿昏,你說(shuō)我怎么就攤上這事峦剔。” “怎么了角钩?”我有些...
    開(kāi)封第一講書(shū)人閱讀 157,490評(píng)論 0 348
  • 文/不壞的土叔 我叫張陵吝沫,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我递礼,道長(zhǎng)惨险,這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 56,521評(píng)論 1 284
  • 正文 為了忘掉前任脊髓,我火速辦了婚禮既荚,結(jié)果婚禮上讽挟,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好初厚,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,627評(píng)論 6 386
  • 文/花漫 我一把揭開(kāi)白布速妖。 她就那樣靜靜地躺著刚夺,像睡著了一般。 火紅的嫁衣襯著肌膚如雪涛贯。 梳的紋絲不亂的頭發(fā)上诽嘉,一...
    開(kāi)封第一講書(shū)人閱讀 49,842評(píng)論 1 290
  • 那天,我揣著相機(jī)與錄音弟翘,去河邊找鬼虫腋。 笑死,一個(gè)胖子當(dāng)著我的面吹牛稀余,可吹牛的內(nèi)容都是我干的悦冀。 我是一名探鬼主播,決...
    沈念sama閱讀 38,997評(píng)論 3 408
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼睛琳,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼盒蟆!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起师骗,我...
    開(kāi)封第一講書(shū)人閱讀 37,741評(píng)論 0 268
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤历等,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后辟癌,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體寒屯,經(jīng)...
    沈念sama閱讀 44,203評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,534評(píng)論 2 327
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了寡夹。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片处面。...
    茶點(diǎn)故事閱讀 38,673評(píng)論 1 341
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖菩掏,靈堂內(nèi)的尸體忽然破棺而出魂角,到底是詐尸還是另有隱情,我是刑警寧澤智绸,帶...
    沈念sama閱讀 34,339評(píng)論 4 330
  • 正文 年R本政府宣布野揪,位于F島的核電站囱挑,受9級(jí)特大地震影響醉顽,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜游添,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,955評(píng)論 3 313
  • 文/蒙蒙 一唆涝、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧廊酣,春花似錦、人聲如沸亡驰。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,770評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)透乾。三九已至,卻和暖如春乳乌,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背汉操。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,000評(píng)論 1 266
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留其弊,地道東北人癞己。 一個(gè)月前我還...
    沈念sama閱讀 46,394評(píng)論 2 360
  • 正文 我出身青樓痹雅,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親绩社。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,562評(píng)論 2 349

推薦閱讀更多精彩內(nèi)容