2016-03-17 70 views
2

我有一个spring-boot启动器web应用程序。最近我一直在获得与类路径中的Logback有关的错误。下面是我目前gradle这个文件:gradle spring引导启动器日志记录失败,Logback错误

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' 
} 

有了这个配置,我可以运行战争或使用bootRun启动该应用程序。然而,我的春天集成测试全部失败

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

我已经看过在互联网上的错误,特别是在这些stackoverflowquestions寻求解决方案。这些问题的问题和答案帮助我能够通过排除Logback来运行应用程序。但是测试仍然失败。 This article,特别帮助我确保logback不在依赖关系树中。当我运行

gradlew -q dependencies --configuration compile 

并查看输出,是的logback无处可在依赖关系树了上述的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"}/ 
} 
} 

TL; DR:我的配置工作运行的战争,但所有的集成测试现在失败。我如何修复我的配置以便再次通过测试?

回答

5

改为目标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")