猿问

Spring Boot/Gradle/Logback:bootRun 失败,并显示“无法实例化

在新的 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)

问题是什么?



蝴蝶不菲
浏览 116回答 3
3回答

跃然一笑

当我检查时gradle dependencyInsight --dependency logback,我看到:> Task :dependencyInsightch.qos.logback:logback-classic:1.1.3 (selected by rule)&nbsp; &nbsp;variant "compile" [&nbsp; &nbsp; &nbsp; org.gradle.status&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = release (not requested)&nbsp; &nbsp; &nbsp; org.gradle.usage&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= java-api&nbsp; &nbsp; &nbsp; org.gradle.libraryelements&nbsp; &nbsp; &nbsp;= jar (compatible with: classes)&nbsp; &nbsp; &nbsp; org.gradle.category&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = library (not requested)&nbsp; &nbsp; &nbsp; Requested attributes not found in the selected variant:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;org.gradle.dependency.bundling = external&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;org.gradle.jvm.version&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 8&nbsp; &nbsp;]ch.qos.logback:logback-classic:1.1.3\--- compileClasspathch.qos.logback:logback-classic:1.2.3 -> 1.1.3\--- org.springframework.boot:spring-boot-starter-logging:2.1.9.RELEASE&nbsp; &nbsp; &nbsp;\--- org.springframework.boot:spring-boot-starter:2.1.9.RELEASE&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +--- compileClasspath (requested org.springframework.boot:spring-boot-starter)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +--- org.springframework.boot:spring-boot-starter-web:2.1.9.RELEASE&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; +--- compileClasspath (requested org.springframework.boot:spring-boot-starter-web)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; \--- org.springframework.boot:spring-boot-starter-websocket:2.1.9.RELEASE&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\--- compileClasspath&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +--- org.springframework.boot:spring-boot-starter-json:2.1.9.RELEASE&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; +--- org.springframework.boot:spring-boot-starter-web:2.1.9.RELEASE (*)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; \--- org.springframework.boot:spring-boot-starter-jersey:2.1.9.RELEASE&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\--- compileClasspath (requested org.springframework.boot:spring-boot-starter-jersey)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \--- org.springframework.boot:spring-boot-starter-validation:2.1.9.RELEASE&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\--- org.springframework.boot:spring-boot-starter-jersey:2.1.9.RELEASE (*)ch.qos.logback:logback-core:1.2.3 (selected by rule)&nbsp; &nbsp;variant "compile" [&nbsp; &nbsp; &nbsp; org.gradle.status&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = release (not requested)&nbsp; &nbsp; &nbsp; org.gradle.usage&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= java-api&nbsp; &nbsp; &nbsp; org.gradle.libraryelements&nbsp; &nbsp; &nbsp;= jar (compatible with: classes)&nbsp; &nbsp; &nbsp; org.gradle.category&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = library (not requested)&nbsp; &nbsp; &nbsp; Requested attributes not found in the selected variant:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;org.gradle.dependency.bundling = external&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;org.gradle.jvm.version&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 8&nbsp; &nbsp;]ch.qos.logback:logback-core:1.1.3 -> 1.2.3\--- ch.qos.logback:logback-classic:1.1.3&nbsp; &nbsp; &nbsp;+--- compileClasspath&nbsp; &nbsp; &nbsp;\--- org.springframework.boot:spring-boot-starter-logging:2.1.9.RELEASE (requested ch.qos.logback:logback-classic:1.2.3)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \--- org.springframework.boot:spring-boot-starter:2.1.9.RELEASE&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+--- compileClasspath (requested org.springframework.boot:spring-boot-starter)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+--- org.springframework.boot:spring-boot-starter-web:2.1.9.RELEASE&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; &nbsp; +--- compileClasspath (requested org.springframework.boot:spring-boot-starter-web)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; &nbsp; \--- org.springframework.boot:spring-boot-starter-websocket:2.1.9.RELEASE&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\--- compileClasspath&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+--- org.springframework.boot:spring-boot-starter-json:2.1.9.RELEASE&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; &nbsp; +--- org.springframework.boot:spring-boot-starter-web:2.1.9.RELEASE (*)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; &nbsp; \--- org.springframework.boot:spring-boot-starter-jersey:2.1.9.RELEASE&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\--- compileClasspath (requested org.springframework.boot:spring-boot-starter-jersey)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\--- org.springframework.boot:spring-boot-starter-validation:2.1.9.RELEASE&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \--- 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 版本。

GCT1015

在资源文件下创建一个 logback-test.xml 文件以及 logback.xml 并仅使用 .&nbsp;它应该有效

MYYA

请尝试将这 3 个依赖项添加到您的 pom.xml 文件中。它对我有用..&nbsp; &nbsp; <dependency>&nbsp; &nbsp; <groupId>ch.qos.logback</groupId>&nbsp; &nbsp; <artifactId>logback-core</artifactId>&nbsp; &nbsp; <version>1.1.3</version>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <dependency>&nbsp; &nbsp; <groupId>ch.qos.logback</groupId>&nbsp; &nbsp; <artifactId>logback-classic</artifactId>&nbsp; &nbsp; <version>1.2.3</version>&nbsp; &nbsp; <scope>compile</scope>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <dependency>&nbsp; &nbsp; <groupId>ch.qos.logback</groupId>&nbsp; &nbsp; <artifactId>logback-core</artifactId>&nbsp; &nbsp; <version>1.2.3</version>&nbsp; &nbsp; <scope>compile</scope>&nbsp; &nbsp; </dependency>
随时随地看视频慕课网APP

相关分类

Java
我要回答