Springboot - 我可以将Jetty与SL4J一起使用

时间:2018-03-09 15:41:51

标签: spring-boot gradle jetty

我正在开发SpringBoot - Kotlin - Gradle项目,我似乎遇到了记录器冲突。我使用的是包含slf4j的图书馆 - 因此在启动时,我发出了以下精彩信息:

  

引起:java.lang.IllegalArgumentException:LoggerFactory不是Logback LoggerContext,但Logback在类路径上。删除Logback或竞争实现(从文件加载的类org.slf4j.impl.Log4jLoggerFactory:/Users/USERNAME/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-log4j12/1.7.25/ 110cefe2df103412849d72ef7a67e4e91e4266b4 / SLF4J-log4j12-1.7.25.jar)。如果您使用的是WebLogic,则需要添加' org.slf4j'更喜欢WEB-INF / weblogic.xml中的application-packages:org.slf4j.impl.Log4jLoggerFactory

将这些行添加到build.gradle文件允许我运行:

configurations {
    providedRuntime
    compile.exclude(group: 'ch.qos.logback')
}

但是我的应用程序现在启动时使用 Tomcat 而不是 Jetty

我的依赖块是:

dependencies {
    compile('org.springframework.boot:spring-boot-starter')
    compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    compile("org.jetbrains.kotlin:kotlin-reflect")
    compile 'org.springframework.boot:spring-boot-starter-web'
    runtime('org.springframework.boot:spring-boot-devtools')
    testCompile('org.springframework.boot:spring-boot-starter-test')


    //SpringFox
    compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.8.0'
    compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.8.0'
    compile group: 'io.springfox', name: 'springfox-spring-web', version: '2.8.0'

    // SDDF
    compile "org.mitre.sddf:sddf:15.3.2"
}

是否有一种简单的方法可以解决此问题并且仍然可以使用 Jetty

我可以在applicaiton.ymlapplictaion.properties中添加某些内容吗?

1 个答案:

答案 0 :(得分:0)

好吧,似乎我设法解决了我的问题(通过稍微阅读日志)

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/jstein/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-log4j12/1.7.25/110cefe2df103412849d72ef7a67e4e91e4266b4/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/jstein/.gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.2.3/7c4f3c474fb2c041d8028740440937705ebb473a/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]

我将此添加到我的build.gradle

configurations.all {
 exclude group: 'org.slf4j', module: 'slf4j-log4j12'
}