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:我的配置工作運行的戰爭,但所有的集成測試現在失敗。我如何修復我的配置以便再次通過測試?