【问题标题】:Gradle exclude SLF4J from SpringGradle 从 Spring 中排除 SLF4J
【发布时间】:2015-04-16 01:10:36
【问题描述】:

好吧,下面的代码可以工作,但看起来不太好。我有一个 Spring Boot 项目,我想排除 SLF4J,因为我想改用 Log4j2。

有人知道如何改进代码吗?

dependencies {
    compile("org.springframework:spring-context") {
        exclude module: "spring-boot-starter-logging"
        exclude module: "logback-classic"
    }
    compile("org.springframework.boot:spring-boot-starter-web") {
        exclude module: "spring-boot-starter-logging"
        exclude module: "logback-classic"
    }
    compile("org.springframework.boot:spring-boot-starter-data-mongodb") {
        exclude module: "spring-boot-starter-logging"
        exclude module: "logback-classic"
    }
    compile("org.springframework.boot:spring-boot-starter-log4j2")
    providedRuntime("org.apache.tomcat.embed:tomcat-embed-jasper")
    testCompile("junit:junit")
}

【问题讨论】:

    标签: spring logging gradle log4j spring-boot


    【解决方案1】:

    你可以例如试试:

    dependencies {
        [
            "org.springframework:spring-context",
            "org.springframework.boot:spring-boot-starter-web",
            "org.springframework.boot:spring-boot-starter-data-mongodb",
        ].each { dep ->
            compile(dep) {
                exclude module: "spring-boot-starter-logging"
                exclude module: "logback-classic"
            }
        }
        compile("org.springframework.boot:spring-boot-starter-log4j2")
        runtime("org.apache.tomcat.embed:tomcat-embed-jasper")
        testCompile("junit:junit")
    }
    

    【讨论】:

    • 接受您的回答,因为这个版本看起来比我的版本好得多,谢谢。 runtime 是否等于providedRuntime?
    • 没有。这些是不同的配置。 runtime 来自java 插件,而providedRuntime 来自war: gradle.org/docs/current/userguide/war_plugin.html。我不知道你的配置,所以我只是将providedRuntime 替换为runtime 以使其工作。
    • 为什么 jar 文件仍然存在于 gradle 缓存中,当它没有出现在 gradle 依赖项中时,因此当我启动我的项目时它仍然显示绑定问题,即使 gradle 依赖项列表没有参考重新登录...有什么想法吗??
    猜你喜欢
    • 1970-01-01
    • 2018-10-19
    • 1970-01-01
    • 2015-11-13
    • 2017-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-17
    相关资源
    最近更新 更多