我在 Java Web 应用程序中使用 renjin 来加载 RData 文件。由于我在公司网络中,我只能从 maven Central 访问包。由于 renjin 托管在不同的存储库中,我从网站下载了独立的 jar (renjin-script-engine-3.5-beta43.jar) 并手动将其安装在我的本地 maven 存储库中。与 Java 的集成工作正常。
我在我的应用程序中使用 slf4j (1.7.28) 作为主要的日志记录 API。但是,当我尝试将 log4j2 (2.12.1) 添加为要使用的日志记录实现时,由于类路径上的多个实现,我在启动时收到 slf4j 警告:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:<project-path>/target/<project-name>-0.0.1-SNAPSHOT/WEB-INF/lib/log4j-slf4j-impl-2.12.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:<project-path>/target/<project-name>-0.0.1-SNAPSHOT/WEB-INF/lib/renjin-script-engine-3.5-beta43.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
似乎 renjin 在编译时包含一个 slf4j 实现,这是 slf4j 建议反对的。由于没有将实现添加为传递依赖项,因此我无法在 maven 中排除它。
slf4j 文档说它应该提到它绑定的实现,但我在这方面没有任何输出。我当前的 log4j2.xml 配置似乎对我看到的日志输出没有影响,但我不知道这是由于配置中的问题还是因为 slf4j 绑定了其他实现。为了正确调试这个,我想修复 slf4j 警告,并且只有 log4j2 作为类路径上的实现。我也看过自己编译 renjin,但它需要一个旧的 gcc 版本(4.7),我无法在我的机器上安装(Ubuntu 18.04.3)。此外,一些构建依赖项位于其他存储库中,由于网络限制,我无法访问。
最新的 renjin jar (beta73) 还包括提到的 slf4j 实现类。这是我应该在 renjin github 页面上提出的问题,还是有其他方法可以在不包含 slf4j 实现的情况下使用 renjin?
作为参考,这是我当前的 pom.xml(我已将项目名称、groupId 和 artifactId 替换为通用占位符):
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId><my-group></groupId>
<artifactId><my-project></artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name><project-name></name>
<description>Backend for LDB</description>
<properties>
<java.version>11</java.version>
<ignite.version>2.7.6</ignite.version>
<!-- Springboot will default to 1.4.199, which will not work with ignite. -->
<h2.version>1.4.197</h2.version>
<log4j2.version>2.12.1</log4j2.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.renjin</groupId>
<artifactId>renjin-script-engine</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>de.grundid.opendatalab</groupId>
<artifactId>geojson-jackson</artifactId>
<version>1.8.1</version>
</dependency>
<!--
The swagger libraries included in springfox contain a bug that will log various NumberFormatExceptions due to not set example values
in ApiModelProperty, when rendering the Swagger UI. To fix this we load a newer version of these swagger libraries.
See: https://github.com/springfox/springfox/issues/2265#issuecomment-413286451
-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
<exclusions>
<exclusion>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
</exclusion>
<exclusion>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.23</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
<version>1.5.23</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<!-- Apache Ignite -->
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-core</artifactId>
<version>${ignite.version}</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-spring</artifactId>
<version>${ignite.version}</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-indexing</artifactId>
<version>${ignite.version}</version>
</dependency>
<!-- Logging Slf4j with log4j2 as the implementation -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-web</artifactId>
<version>${log4j2.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>