gpt4 book ai didi

gradle spring boot starter-logging 因 Logback 错误而失败

转载 作者:行者123 更新时间:2023-12-01 10:35:38 26 4
gpt4 key购买 nike

我有一个 spring-boot starter 网络应用程序。最近我收到了与类路径上的 Logback 相关的错误。下面是我当前的 gradle 文件:

buildscript {
ext {
springBootVersion = '1.3.1.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath('io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE')
classpath 'net.saliman:gradle-cobertura-plugin:2.3.0'
}
}

apply plugin: 'groovy'
apply plugin: 'spring-boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'


repositories {
mavenCentral()
}

configurations {
providedRuntime
}

configurations {
all*.exclude module: 'spring-boot-starter-logging'
}

dependencies {
compile 'com.github.groovy-wslite:groovy-wslite:1.1.2'
compile('org.springframework.boot:spring-boot-starter-web')

compile("org.springframework.boot:spring-boot-starter-data-rest")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile('org.springframework.boot:spring-boot-starter-log4j')
compile('org.codehaus.groovy:groovy')
compile("org.apache.accumulo:accumulo-core:1.6.2") {
exclude module: "slf4j-log4j12"
}

compile("com.h2database:h2")

providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
testCompile('org.springframework.boot:spring-boot-starter-test')

testCompile 'com.github.groovy-wslite:groovy-wslite:1.1.2'
testCompile 'org.codehaus.groovy:groovy-json:2.4.5'
testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
testCompile 'org.spockframework:spock-spring:1.0-groovy-2.4'
testCompile 'cglib:cglib-nodep:3.1'

}

tasks.withType(Test) {
systemProperty 'spring.profiles.active', 'test'
}

使用此配置,我可以运行 war 或使用 bootRun 来启动应用程序。但是,我的 spring 集成测试全部失败并出现错误

Caused by: java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation

我查看了互联网,特别是这些 stack overflow questions寻求解决方案。这些问题的问题和答案帮助我能够通过排除 Logback 来运行应用程序。然而,测试仍然失败。 This article ,特别是帮助我确保 logback 不在依赖树中。当我运行时

gradlew -q dependencies --configuration compile

并查看输出,上面的 build.gradle 文件不再在依赖树中找到 logback。但是,像下面这样运行 Spring 集成测试会失败,并显示上面粘贴的错误消息:

@SpringApplicationConfiguration(classes = Application.class, initializers = ConfigFileApplicationContextInitializer.class)
@WebIntegrationTest
class CanaryIntegrationSpec extends Specification {
@Value('${local.server.port}') int port

def "when we call single test endpoint then we get a response back"() {
when:
ResponseEntity entity = new RestTemplate().getForEntity("http://localhost:$port/query/test", String.class)

then:
entity.statusCode == HttpStatus.OK
entity.body == /{"hello":"world"}/
}
}

TL;DR:我的配置适用于运行 war ,但所有集成测试现在都失败了。我怎样才能修复我的配置,以便测试再次通过?

最佳答案

改为目标 logback。替换:

configurations {
all*.exclude module: 'spring-boot-starter-logging'
}

与:

configurations {
all*.exclude module: 'spring-boot-starter-logging'
all*.exclude module: "logback-classic"
}

并从 Accumulo 中移除排除项。即替换:

compile("org.apache.accumulo:accumulo-core:1.6.2") {
exclude module: "slf4j-log4j12"
}

与:

compile("org.apache.accumulo:accumulo-core:1.6.2")

关于gradle spring boot starter-logging 因 Logback 错误而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36063183/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com