如何在 Quarkus 中修复 "No suitable Log implementation"

How to fix "No suitable Log implementation" in Quarkus

我有一个使用本机编译的 Quarkus 应用程序,当我尝试记录任何内容时出现错误:

Exception message: org.apache.commons.logging.LogConfigurationException: No suitable Log implementation

我该如何解决这个问题?

根据讨论 here,我使用 ./mvnw dependency:tree | grep -B 4 "commons-logging" 生成的依赖关系树找到导入 Apache 日志库的 类。结果对我来说是 HTTP 客户端,所以我需要在 pom.xml 文件中排除那些:

<dependency>
  <artifactId>httpclient</artifactId>
  <groupId>org.apache.httpcomponents</groupId>
  <version>4.5.13</version>
  <exclusions>
    <exclusion>
      <artifactId>commons-logging</artifactId>
      <groupId>commons-logging</groupId>
    </exclusion>
  </exclusions>
</dependency>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>jcl-over-slf4j</artifactId>
  <version>1.7.30</version>
</dependency>

此配置由 this answer 提供。

您也可以使用:

<dependency>
  <groupId>io.quarkus</groupId>
  <artifactId>quarkus-apache-httpclient</artifactId>
</dependency>

它导致它打包 httpclient 与 Quarkus 一起使用的日志记录。