gradle spring boot starter-logging失败并出现Logback错误

ade*_*ady 3 gradle spring-boot

我有一个spring-boot启动web应用程序.最近我收到了与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'
}
Run Code Online (Sandbox Code Playgroud)

使用此配置,我可以运行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
Run Code Online (Sandbox Code Playgroud)

我已经浏览了互联网,特别是在这些堆栈 溢出 问题的解决方案.这些问题的问题和答案帮助我能够通过排除Logback来运行应用程序.然而,测试仍然失败. 本文特别帮助我确保了logback不在依赖树中.我跑的时候

gradlew -q dependencies --configuration compile
Run Code Online (Sandbox Code Playgroud)

并查看输出,使用上面的build.gradle文件无法在依赖关系树中找到回溯.但是,运行如下所示的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"}/
}
}
Run Code Online (Sandbox Code Playgroud)

TL; DR:我的配置适用于运行战争,但所有集成测试现在都失败了.如何修复配置以便测试再次通过?

小智 6

目标回溯.更换:

configurations {
    all*.exclude module: 'spring-boot-starter-logging'
}
Run Code Online (Sandbox Code Playgroud)

附:

configurations {
    all*.exclude module: 'spring-boot-starter-logging'
    all*.exclude module: "logback-classic"
}
Run Code Online (Sandbox Code Playgroud)

并从Accumulo中删除排除.那就是取代:

compile("org.apache.accumulo:accumulo-core:1.6.2") {
    exclude module: "slf4j-log4j12"
}
Run Code Online (Sandbox Code Playgroud)

有:

compile("org.apache.accumulo:accumulo-core:1.6.2")
Run Code Online (Sandbox Code Playgroud)


归档时间:

查看次数:

1701 次

最近记录:

9 年,5 月 前