spring - Gradle 从 Spring 中排除 SLF4J

标签 spring logging gradle log4j spring-boot

好吧,下面的代码有效,但看起来不太好。我有一个 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")
}

最佳答案

你可以例如尝试:

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")
}

关于spring - Gradle 从 Spring 中排除 SLF4J,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28525927/

相关文章:

CSS 映射与 spring 3.2.4 MVC - 无 web.xml

java.util.logging 在 Gwt 和 Glassfish 中不起作用

java - 尝试创建 Google Cloud Module 时的 Android Studio 1.3 Beta 1 错误

java - 如何 Autowiring 具有多个实现的接口(interface)

java - Spring JPA REST 按嵌套属性排序

java - 寻找与数据库设计相关的方式

java - Gradle:如何从 WAR 中排除 JAR?

spring-boot - 无法使Netbeans Project确认现有的Tomcat或Glassfish服务器

java - 将 UserDetails 添加到 SecurityContextHolder

c# - log4net:不同类型的不同信息颜色