Java LoggerFactory 不是 Logback LoggerContext 但 Logback 在类路径上
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30792268/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
LoggerFactory is not a Logback LoggerContext but Logback is on the classpath
提问by newbie
I think some module in spring-boot-starter-security is conflict with log4j, but I don't know which one.
我认为 spring-boot-starter-security 中的某些模块与 log4j 冲突,但我不知道是哪个模块。
my gradle dependence is as following:
我的gradle依赖如下:
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-starter-security"){
exclude module: "spring-boot-starter-logging"
}
compile "org.apache.logging.log4j:log4j-api"
compile "org.apache.logging.log4j:log4j-core"
compile "org.apache.logging.log4j:log4j-slf4j-impl"
compile('org.apache.poi:poi:3.10.1')
compile('org.apache.poi:poi-ooxml:3.10.1')
testCompile("junit:junit")
采纳答案by newbie
i figured out
我想通了
compile("org.springframework.boot:spring-boot-starter-security"){
exclude module: "spring-boot-starter-logging"
exclude module: "logback-classic"
}
compile("org.springframework.boot:spring-boot-starter-thymeleaf"){
exclude module: "logback-classic"
}
回答by ufukomer
Same solution for maven:
Maven 的相同解决方案:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>1.5.1.RELEASE</version>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>
回答by Robin Wang
Using the IDEA "Show Dependencies" or mvn dependency:tree -Dverbose
to find all the logback-classic jar file, and exclude them.
使用 IDEA“显示依赖项”或mvn dependency:tree -Dverbose
查找所有 logback-classic jar 文件,并排除它们。
回答by michals
For me this problem appeared only during execution of maven-surefire-plugin. Somehow Logback is there on the class path, even if its not added to project dependencies. I added such fix:
对我来说,这个问题只出现在 maven-surefire-plugin 的执行过程中。不知何故,类路径上有 Logback,即使它没有添加到项目依赖项中。我添加了这样的修复:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<systemPropertyVariables>
<org.springframework.boot.logging.LoggingSystem>
org.springframework.boot.logging.log4j2.Log4J2LoggingSystem
</org.springframework.boot.logging.LoggingSystem>
</systemPropertyVariables>
</configuration>
</plugin>
You can also use
你也可以使用
mvn clean install -Dorg.springframework.boot.logging.LoggingSystem=org.springframework.boot.logging.log4j2.Log4J2LoggingSystem
回答by rupweb
The problem for me went on with: Either remove Logback or the competing implementation class org.apache.logging.slf4j.Log4jLoggerFactory loaded from log4j-slf4j-impl-2.12.0.jar
我的问题是:删除 Logback 或从 log4j-slf4j-impl-2.12.0.jar 加载的竞争实现类 org.apache.logging.slf4j.Log4jLoggerFactory
I added
我加了
configurations {
all {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
exclude group: 'ch.qos.logback', module: 'logback-classic'
exclude group: 'org.apache.logging.log4j', module: 'log4j-to-slf4j'
}
}
to my gradle.build and also refreshed all project dependencies with the latest versions and the problem resolved.
到我的 gradle.build 并使用最新版本刷新所有项目依赖项,问题已解决。