这对我很有用
configurations { all*.exclude module : 'spring-boot-starter-logging' }
但它不会有用 的 行家 强> 用户。我的所有依赖项都在libs.gradle中,我不想在其他文件中使用它们。所以这 的 问题解决了 强> 通过增加 exclude module : 'spring-boot-starter-logging 在 spring-boot-starter-data-jpa , spring-boot-starter-test 几乎所有的东西都有引导词。
exclude module : 'spring-boot-starter-logging
spring-boot-starter-data-jpa
spring-boot-starter-test
的 UPDATE 强>
事实证明,我的新项目需要更新 spring-boot-starter-test 1.5岁以上没有 spring-boot-starter-logging 。 2.0有它
spring-boot-starter-logging
在build.gradle中添加它
configurations.all { exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat' exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging' exclude group: 'org.springframework.boot', module: 'logback-classic' }
在Gradle中添加更好,更通用的解决方案(将排除所有实例):
从 https://docs.gradle.org/current/userguide/dependency_management.html
我发现排除了全部 spring-boot-starter-logging 模块不是必需的。所需要的只是排除 org.slf4j:slf4j-log4j12 模块。
org.slf4j:slf4j-log4j12
将其添加到Gradle构建文件将解决此问题:
configurations { runtime.exclude group: "org.slf4j", module: "slf4j-log4j12" compile.exclude group: "org.slf4j", module: "slf4j-log4j12" }
查看其他StackOverflow 回答 更多细节。
我通过以下方式解决了我的问题:
compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.0'){ exclude module: 'log4j-slf4j-impl' exclude module: 'logback-classic' } compile('org.springframework.boot:spring-boot-starter-web'){ exclude module: 'log4j-slf4j-impl' exclude module: 'logback-classic' }
如果您说出您的首选记录器完全正确,以及您尝试安装它所做的工作,这可能会有所帮助。无论如何,Spring Boot尝试使用类路径中的任何内容,因此如果您不想进行回溯,请将其从类路径中删除。有log4j的说明 在文档中 ,但同样的事情适用于其他支持的日志系统(任何slf4j,log4j或java util)。
如果在尝试使用log4j2时SpringBoot中发生此错误 执行以下步骤:
发生此错误是因为logback覆盖了log4j2更改。因此,如果要使用log4j2,则必须删除logback库和依赖项。
希望这会对某人有所帮助。
在spring-boot-starter和spring-boot-starter-web中添加排除项以解决冲突。
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency>
在pom.xml中找到spring-boot-starter-test并按如下方式修改它:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <exclusions> <exclusion> <artifactId>commons-logging</artifactId> <groupId>commons-logging</groupId> </exclusion> </exclusions> <scope>test</scope> </dependency>
它修复了如下错误:
引起:java.lang.IllegalArgumentException: 的 的LoggerFactory 强> 不是一个 的 Logback LoggerContext 强> 但 的logback 在类路径上。
要么删除 的 的logback 强> 或竞争实施
( class org.apache.logging.slf4j.Log4jLoggerFactory 从文件加载: 的 $ {M2_HOME} /repository/org/apache/logging/log4j/log4j-slf4j-impl/2.6.2/log4j-slf4j-impl-2.6.2.jar 强> )。
如果您使用的是WebLogic,则需要添加 的 'org.slf4j' 强> 更喜欢WEB-INF / weblogic.xml中的application-packages: 的 org.apache.logging.slf4j.Log4jLoggerFactory 强>
只需在类路径中添加logback.xml配置,并添加添加了root appender的所有配置。一旦Spring引导完成bean加载,它将根据您的配置开始记录。
在gradle中添加解决方案。
dependencies { compile ('org.springframework.boot:spring-boot-starter') { exclude module : 'spring-boot-starter-logging' } compile ('org.springframework.boot:spring-boot-starter-web') { exclude module : 'spring-boot-starter-logging' } }
以下为我工作
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency>
我喜欢这样来解决我的问题
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-log4j</artifactId> <exclusions> <exclusion> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </exclusion> </exclusions> </dependency>