[英]Spring - SpringJUnit4ClassRunner still using LOG4J 1 instead of 2?
I am using the SpringRunner
class to guide my IT tests:我正在使用SpringRunner
类来指导我的 IT 测试:
@ContextConfiguration(loader = AnnotationConfigContextLoader.class, classes = MyTestConfiguration.class)
@RunWith(SpringRunner.class)
class SomeTestIT {
// tests here
}
@Configuration
public class MyTestConfiguration {
}
I have the following Maven dependencies for log4j2:我对 log4j2 有以下 Maven 依赖项:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-bom</artifactId>
<version>2.9.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.0.1.RELEASE</version>
<scope>test</scope>
</dependency>
My log4j2.xml
looks as following:我的log4j2.xml
如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration strict="true" monitorInterval="30" status="error">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%5p | %d | %F | %L | %m%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="error">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
I have put this log4j2.xml
in src/test/resources
.我已将此log4j2.xml
放在src/test/resources
。
Now, when the tests are running, I get the following warnings:现在,当测试运行时,我收到以下警告:
log4j:WARN No appenders could be found for logger (org.springframework.test.context.junit4.SpringJUnit4ClassRunner).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
For some reason I cannot find, my log4j2 configuration is not being used for loggings from SpringRunner
.由于某种原因,我找不到,我的 log4j2 配置没有用于SpringRunner
。 How can I debug and hopefully fix this?我该如何调试并希望解决这个问题?
update更新
I do not think it is related, but just in case: I have also following dependencies:我不认为它是相关的,但以防万一:我还有以下依赖项:
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
</dependency>
This is old log4j binding:这是旧的 log4j 绑定:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
</dependency>
Here slf4j-log4j12
states for slf4j over log4j v1.2这里slf4j-log4j12
声明了 slf4j over log4j v1.2
You should update your slf4j binding to您应该将 slf4j 绑定更新为
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.9.1</version>
</dependency>
Latest version is 2.9.1.最新版本是 2.9.1。 Version earlier than 2.9.0 doesn't match your SLF4J API version.早于 2.9.0 的版本与您的 SLF4J API 版本不匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.