亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Spring Boot/Gradle/Logback:bootRun 失敗,并顯示“無法實例化

Spring Boot/Gradle/Logback:bootRun 失敗,并顯示“無法實例化

蝴蝶不菲 2023-09-27 16:08:15
在新的 Spring Boot 應用程序中,當我 時gradle bootRun,我看到以下錯誤:Failed to instantiate [ch.qos.logback.classic.LoggerContext]Reported exception:java.lang.AbstractMethodError: ch.qos.logback.classic.pattern.EnsureExceptionHandling.process(Lch/qos/logback/core/Context;Lch/qos/logback/core/pattern/Converter;)V    at ch.qos.logback.core.pattern.PatternLayoutBase.start(PatternLayoutBase.java:86)    at ch.qos.logback.classic.encoder.PatternLayoutEncoder.start(PatternLayoutEncoder.java:28)    at ch.qos.logback.classic.BasicConfigurator.configure(BasicConfigurator.java:50)    at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:164)    at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:85)    at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)    at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)    at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)    at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412)    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)    at com.klarna.risk.decision.application.RiskDecisionApplication.<clinit>(RiskDecisionApplication.java:14)問題是什么?
查看完整描述

3 回答

?
躍然一笑

TA貢獻1826條經驗 獲得超6個贊

當我檢查時gradle dependencyInsight --dependency logback,我看到:


> Task :dependencyInsight

ch.qos.logback:logback-classic:1.1.3 (selected by rule)

   variant "compile" [

      org.gradle.status              = release (not requested)

      org.gradle.usage               = java-api

      org.gradle.libraryelements     = jar (compatible with: classes)

      org.gradle.category            = library (not requested)


      Requested attributes not found in the selected variant:

         org.gradle.dependency.bundling = external

         org.gradle.jvm.version         = 8

   ]


ch.qos.logback:logback-classic:1.1.3

\--- compileClasspath


ch.qos.logback:logback-classic:1.2.3 -> 1.1.3

\--- org.springframework.boot:spring-boot-starter-logging:2.1.9.RELEASE

     \--- org.springframework.boot:spring-boot-starter:2.1.9.RELEASE

          +--- compileClasspath (requested org.springframework.boot:spring-boot-starter)

          +--- org.springframework.boot:spring-boot-starter-web:2.1.9.RELEASE

          |    +--- compileClasspath (requested org.springframework.boot:spring-boot-starter-web)

          |    \--- org.springframework.boot:spring-boot-starter-websocket:2.1.9.RELEASE

          |         \--- compileClasspath

          +--- org.springframework.boot:spring-boot-starter-json:2.1.9.RELEASE

          |    +--- org.springframework.boot:spring-boot-starter-web:2.1.9.RELEASE (*)

          |    \--- org.springframework.boot:spring-boot-starter-jersey:2.1.9.RELEASE

          |         \--- compileClasspath (requested org.springframework.boot:spring-boot-starter-jersey)

          \--- org.springframework.boot:spring-boot-starter-validation:2.1.9.RELEASE

               \--- org.springframework.boot:spring-boot-starter-jersey:2.1.9.RELEASE (*)


ch.qos.logback:logback-core:1.2.3 (selected by rule)

   variant "compile" [

      org.gradle.status              = release (not requested)

      org.gradle.usage               = java-api

      org.gradle.libraryelements     = jar (compatible with: classes)

      org.gradle.category            = library (not requested)


      Requested attributes not found in the selected variant:

         org.gradle.dependency.bundling = external

         org.gradle.jvm.version         = 8

   ]


ch.qos.logback:logback-core:1.1.3 -> 1.2.3

\--- ch.qos.logback:logback-classic:1.1.3

     +--- compileClasspath

     \--- org.springframework.boot:spring-boot-starter-logging:2.1.9.RELEASE (requested ch.qos.logback:logback-classic:1.2.3)

          \--- org.springframework.boot:spring-boot-starter:2.1.9.RELEASE

               +--- compileClasspath (requested org.springframework.boot:spring-boot-starter)

               +--- org.springframework.boot:spring-boot-starter-web:2.1.9.RELEASE

               |    +--- compileClasspath (requested org.springframework.boot:spring-boot-starter-web)

               |    \--- org.springframework.boot:spring-boot-starter-websocket:2.1.9.RELEASE

               |         \--- compileClasspath

               +--- org.springframework.boot:spring-boot-starter-json:2.1.9.RELEASE

               |    +--- org.springframework.boot:spring-boot-starter-web:2.1.9.RELEASE (*)

               |    \--- org.springframework.boot:spring-boot-starter-jersey:2.1.9.RELEASE

               |         \--- compileClasspath (requested org.springframework.boot:spring-boot-starter-jersey)

               \--- org.springframework.boot:spring-boot-starter-validation:2.1.9.RELEASE

                    \--- org.springframework.boot:spring-boot-starter-jersey:2.1.9.RELEASE (*)


(*) - dependencies omitted (listed previously)


A web-based, searchable dependency report is available by adding the --scan option.

似乎 Spring Boot 2.1.9 正在使用org.springframework.boot:spring-boot-starter-logging:2.1.9.RELEASE,它使用logback-classic:1.1.3. Google 的某個地方告訴我 Spring Boot 依賴管理有一個錯誤,該錯誤允許logback-core和logback-classic在這里出現不同的版本并導致沖突。


我添加了依賴項logback-core:1.1.3,問題就消失了。


compile group: 'ch.qos.logback', name: 'logback-core', version: '1.1.3'

如果您遇到同樣的問題,請務必檢查 Spring Boot 中使用的 logback 版本。


查看完整回答
反對 回復 2023-09-27
?
GCT1015

TA貢獻1827條經驗 獲得超4個贊

在資源文件下創建一個 logback-test.xml 文件以及 logback.xml 并僅使用 . 它應該有效



查看完整回答
反對 回復 2023-09-27
?
MYYA

TA貢獻1868條經驗 獲得超4個贊

請嘗試將這 3 個依賴項添加到您的 pom.xml 文件中。它對我有用..


    <dependency>

    <groupId>ch.qos.logback</groupId>

    <artifactId>logback-core</artifactId>

    <version>1.1.3</version>

    </dependency>


    <dependency>

    <groupId>ch.qos.logback</groupId>

    <artifactId>logback-classic</artifactId>

    <version>1.2.3</version>

    <scope>compile</scope>

    </dependency>


    <dependency>

    <groupId>ch.qos.logback</groupId>

    <artifactId>logback-core</artifactId>

    <version>1.2.3</version>

    <scope>compile</scope>

    </dependency>


查看完整回答
反對 回復 2023-09-27
  • 3 回答
  • 0 關注
  • 155 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號