我在我的项目中使用 log4j2 和 slf4j 并使用 maven 进行构建。我正在使用以下 pom 文件(仅显示相关依赖项),但我在下面使用此 pom 文件复制了错误 - 知道我需要添加/删除什么才能使其正常工作。我已经访问了错误中的 url 以及 log4j2 依赖项页面,所以请不要只在您的回复中指向 URL。
消息:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
pom 文件
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<slf4j.version>1.7.7</slf4j.version>
</properties>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.0.1</version>
</dependency>
更新: 我在我的 pom 文件中添加了以下依赖项,我在我的 mavenrepository 中看到了 jar - 虽然我在运行 mvn clean/install 时仍然看到相同的消息
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.0.1</version>
</dependency>
最佳答案
您的 pom 文件中似乎缺少以下内容。
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.0.1</version>
</dependency>
关于java - slf4j & log4j2 maven 设置查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25386651/