首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >gradle弹簧引导启动器-日志记录失败与登录错误

gradle弹簧引导启动器-日志记录失败与登录错误
EN

Stack Overflow用户
提问于 2016-03-17 14:16:31
回答 1查看 3K关注 0票数 3

我有一个弹簧启动的网络应用程序。最近,我收到了与Logback在类路径上相关的错误。下面是我当前的分级文件:

代码语言:javascript
复制
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启动应用程序。然而,我的春季集成测试都失败了的错误。

代码语言:javascript
复制
Caused by: java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation

我已经浏览过互联网,特别是在堆栈 溢出 问题上寻找一个解决方案。关于这些问题的问题和答案帮助我通过排除Logback来运行应用程序。然而,这些测试仍然失败。尤其是这篇文章帮助我确保logback不在依赖树中。当我跑的时候

代码语言:javascript
复制
gradlew -q dependencies --configuration compile

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

代码语言:javascript
复制
@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,但是现在所有的集成测试都失败了。我如何修正我的配置,使测试再次通过?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-03-17 19:59:21

而是目标登录。取代:

代码语言:javascript
复制
configurations {
    all*.exclude module: 'spring-boot-starter-logging'
}

通过以下方式:

代码语言:javascript
复制
configurations {
    all*.exclude module: 'spring-boot-starter-logging'
    all*.exclude module: "logback-classic"
}

并从Accumulo中移除。即改为:

代码语言:javascript
复制
compile("org.apache.accumulo:accumulo-core:1.6.2") {
    exclude module: "slf4j-log4j12"
}

通过以下方式:

代码语言:javascript
复制
compile("org.apache.accumulo:accumulo-core:1.6.2")
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36063183

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档