SLF4J在运行集成测试时未找到任何提供程序



我有一个使用Spring引导的项目,它有三个不同的sourceSet(main、test和integration test(。集成测试源集在相应的Gradle文件中以这种方式定义:

sourceSets {
main {
java {
srcDir "$buildDir/generated/server/src/main/java"
}
}
integrationTest {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir 'src/integration-test/java'
}
resources.srcDir 'src/integration-test/resources'
}
}

我面临的问题是,当我运行集成测试套件时,应用程序启动,但没有任何记录。事实上,我收到了以下警告:

SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.
SLF4J: Class path contains SLF4J bindings targeting slf4j-api versions 1.7.x or earlier.
SLF4J: Ignoring binding found at [jar:file:/Users/akourtesas/.gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.2.11/4741689214e9d1e8408b206506cbe76d1c6a7d60/logback-classic-1.2.11.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See https://www.slf4j.org/codes.html#ignoredBindings for an explanation.

我试过调试这个,但我不知道发生了什么。我已经打印了mainintegrationTest源集的类路径,我可以肯定地说,SLF4J版本是1.7.36,我的Logback版本是1.2.11。我没有自定义配置或任何奇怪的地方,所以除了集成测试之外,这在所有情况下都能正常工作,这似乎更奇怪。作为参考,我的Spring Boot版本是2.7.5。

过去有人遇到过这种情况吗?如果是,需要做些什么来解决这个问题?

如果您正在使用gradle,请添加此依赖项

implementation 'org.apache.logging.log4j:log4j-slf4j2-impl:2.20.0'

最新更新