gpt4 book ai didi

java - SpringBoot应用程序中增强Log4J2版本

转载 作者:太空宇宙 更新时间:2023-11-04 10:53:31 24 4
gpt4 key购买 nike

尝试在 Spring Boot APP 中使用最新版本的 Log4J2 版本 2.10。

我们是一个微服务解决方案,因此首先创建一个可重用的模块,其详细信息如下 -

可复用日志组件(POM片段如下)-

    <log4j.version>2.10.0</log4j.version>
<commons-logging.version>1.2</commons-logging.version>

<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>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>${commons-logging.version}</version>
</dependency>

微服务项目将其称为 -

     <log4j.version>2.10.0</log4j.version>
<commons-logging.version>1.2</commons-logging.version>
<dependency>
<groupId>a.b.c</groupId>
<artifactId>reusable-logger-starter</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>

无论将 jar 版本覆盖到 2.10.0,它都会显示 2.7.0 -

enter image description here问题 1 -> 这正常吗?

我的解决方法是将以下 jar 包含到微服务的 POM 文件中

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>a.b.c</groupId>
<artifactId>reusable-logger-starter</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>

问题2)有人遇到过类似的问题吗?

最佳答案

解决方案是在微服务的 POM 中包含/覆盖 log4j2 的版本 -

      <properties>
<log4j2.version>
2.10.0
</log4j2.version>
</properties>

Dependency mediation - this determines what version of a dependency will be used when multiple versions of an artifact are encountered. Currently, Maven 2.0 only supports using the "nearest definition" which means that it will use the version of the closest dependency to your project in the tree of dependencies. You can always guarantee a version by declaring it explicitly in your project's POM. Note that if two dependency versions are at the same depth in the dependency tree, until Maven 2.0.8 it was not defined which one would win, but since Maven 2.0.9 it's the order in the declaration that counts: the first declaration wins. "nearest definition" means that the version used will be the closest one to your project in the tree of dependencies, eg. if dependencies for A, B, and C are defined as A -> B -> C -> D 2.0 and A -> E -> D 1.0, then D 1.0 will be used when building A because the path from A to D through E is shorter. You could explicitly add a dependency to D 2.0 in A to force the use of D 2.0

关于java - SpringBoot应用程序中增强Log4J2版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47545000/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com