为了账号安全,请及时绑定邮箱和手机立即绑定

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 关注
  • 108 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信