从 JDK8 迁移到 JDK11 后的"SLF4J: No SLF4J providers were found"



从JDK8迁移到JDK11后,我得到了"SLF4J:没有找到SLF4J提供程序"而不是记录。使用Maven和IntelliJ.

输出:

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.

在JDK8中,我在pom.xml中有这些,并且它们都运行得很好。

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.7</version>
</dependency>

我环顾四周,按照提示添加了slf4j18-impl,但我仍然有同样的问题。这是它现在在pom.xml中的样子:

<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.19.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.19.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.19.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j18-impl</artifactId>
<version>2.18.0</version>
</dependency>

这种代码在JDK8中可以工作,但在JDK11中不行


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestOutput {
private static final Logger LOG = LoggerFactory.getLogger(TestOutput.class);
public static void tryToLog() {
LOG.info("Hello world!");
}
}
<代码>

仅为slf4j添加一个依赖项:

PP_7

相关内容

  • 没有找到相关文章

最新更新