现象:java -jar cas.war 启动即抛 NoSuchMethodError: ThreadContext.getThreadContextMap, WAR 的 WEB-INF/lib 同时存在 log4j api/core/slf4j-impl 的 2.7 与 2.12.1 两套。 根因:spring-boot-dependencies 1.5.18 经内嵌 log4j-bom 管理 log4j 版本,默认 2.7; BOM import 方式下 pom 覆盖 <log4j2.version> 属性不生效(属性在导入 BOM 自身上下文解析), maven 仍解析出 2.7 全套,与 overlay war 物理自带的 2.12.1 混包,类加载顺序决定成败。 修复:dependencyManagement 最前(先声明者优先)import log4j-bom 2.12.1, 全套 log4j 钉死 2.12.1,与 overlay war 内物理版本一致,war 内仅剩单套。
This commit is contained in:
@@ -36,6 +36,19 @@
|
|||||||
<!-- ===== 新增 Dependency Management ===== -->
|
<!-- ===== 新增 Dependency Management ===== -->
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<!-- log4j 全套钉死 2.12.1(与 overlay war 内物理自带版本一致)。
|
||||||
|
关键:spring-boot-dependencies 1.5.18 经 log4j-bom 管 log4j 版本,其属性 log4j2.version 默认 2.7,
|
||||||
|
且 BOM import 方式下在 pom properties 里覆盖 <log4j2.version> 不生效(属性在导入 BOM 自身上下文解析)。
|
||||||
|
此处把 log4j-bom 2.12.1 放在 spring-boot-dependencies 之前 import(先声明者优先),
|
||||||
|
否则 maven 会解析出 2.7 全套、与 overlay war 自带的 2.12.1 物理文件混包,
|
||||||
|
运行期 api/core 版本错配 → NoSuchMethodError: ThreadContext.getThreadContextMap -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-bom</artifactId>
|
||||||
|
<version>2.12.1</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-dependencies</artifactId>
|
<artifactId>spring-boot-dependencies</artifactId>
|
||||||
|
|||||||
Reference in New Issue
Block a user