gpt4 book ai didi

java - 在 Spring Boot 启动器中覆盖 log4j2 版本

转载 作者:行者123 更新时间:2023-11-30 07:04:23 24 4
gpt4 key购买 nike

我们正在尝试构建一个 Springboot 启动器,它将以编程方式创建 log4j2 配置,因此开发人员不必费心创建 log4j2.xml 文件。问题在于 log4j2 编程 API 随版本的不同而变化。我们已经使用 log4j2 2.5 版测试了我们的代码,它在独立环境中正常工作

现在我们正在尝试将我们的 API 包含在 Springboot 启动器中,以便所有 springboot 应用程序都可以包含此启动器,而不必担心 log4j 配置。

我们面临的问题是 Springboot 捆绑了自己的 log4j 版本,我们无法控制用户将使用哪个版本的 Springboot。

有没有一种方法可以强制 springboot 启动器加载 log4j2 2.5 版本,否则我们的测试 Springboot 应用程序会提示 log4j 中找不到某些方法

最佳答案

It is convenient to add log4j2 dependency to section in parent project, as below
<dependencyManagement>
<dependencies>
...
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j</artifactId>
<version>2.15.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
...
</dependencies>
</dependencyManagement>

It will stipulate all log4j 2 versions in the project and modules.Instead, it's not necessary to add some log4j2 dependencyindependently.

检查this question post

If the project's log4j dependencies are only fromspring-boot-starter-log4j2, it has a definitive setting way, refer tospringblog

<properties>
<log4j2.version>2.17.0</log4j2.version>
</properties>

关于java - 在 Spring Boot 启动器中覆盖 log4j2 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40390517/

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