与 Micronaut 和 Apache Beam 的 Maven 项目中的 SLF4J 实现冲突

问题描述 投票:0回答:1

Stack Overflow 社区您好,

我正在使用 Micronaut 4 和 Apache Beam 开发 Maven 项目,面临 SLF4J 日志记录问题。尽管我的依赖项中有

logback-classic
,但我遇到了标准 SLF4J 错误:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation

我尝试从各种依赖项中排除

org.slf4j
,但问题仍然存在。当我删除
beam-sdks-java-io-google-cloud-platform
时,日志记录可以正常工作,表明存在冲突。我还注意到类路径中的
slf4j-simple
,这可能是导致问题的原因。这是我的 pom.xml 的片段:

    <dependency>
      <groupId>org.apache.beam</groupId>
      <artifactId>beam-sdks-java-io-google-cloud-platform</artifactId>
      <version>${beam.version}</version>
    </dependency>

可以从 https://github.com/j1cs/logback-error 克隆该项目。要运行该项目,请使用:

./mvnw mn:run -DskipTests=true

预期的日志输出应该是:

00:14:57.306 [main] INFO  i.m.c.DefaultApplicationContext$RuntimeConfiguredEnvironment - Established active environments: [cli]
00:14:57.308 [main] INFO  i.m.c.DefaultApplicationContext$BootstrapEnvironment - Established active environments: [cli]
00:14:57.328 [main] INFO  i.m.context.DefaultBeanContext - Reading bootstrap environment configuration

有人可以提供有关解决此设置中的 SLF4J 实现冲突的见解或建议吗?

谢谢!

java maven apache-beam micronaut
1个回答
0
投票

更换好:

    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <scope>runtime</scope>
    </dependency>

    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-slf4j-impl</artifactId>
      <version>2.12.1</version>
      <scope>runtime</scope>
    </dependency>

并在

log4j2.xml
中添加
src/main/resources
现在我可以看到日志了。

© www.soinside.com 2019 - 2024. All rights reserved.