gpt4 book ai didi

spring - Intelli j idea调试时tomcat加载低版本spring库

转载 作者:行者123 更新时间:2023-11-28 23:12:12 25 4
gpt4 key购买 nike

我有一个用目标 war 构建的 maven spring web(3.2.*) 项目,我想用 tomcat 在 intellij idea 中调试它(web:war exploded artifact),但是 web 应用程序总是加载失败,

[ERROR]..|Context initialization failed java.lang.NoSuchMethodError: org.springframework.web.context.ConfigurableWebApplicationContext.getEnvironment()Lorg/springframework/core/env/ConfigurableEnvironment; at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:404)

因为在一些pom依赖中,它们引用了较低版本的spring(3.0.7),我可以用maven-war-plugin(2.3):packagingExcludes在ware中排除它们,但是我如何在web:war exploded中排除它们.

<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<packagingExcludes>
WEB-INF/lib/org.springframework.core-3.0.7.RELEASE.jar,
// others springframework jars
</packagingExcludes>
</configuration>
</plugin>

最佳答案

Maven 有一个不容易理解的方式来解决依赖冲突。它叫做 nearest-wins strategy ,这可能会导致使用旧版本。

尝试使用Maven Dependency Management结合 Maven Enforcer Plugin如果您没有明确定义依赖版本,则固定版本并使构建失败。

最简单的方法是 analyse the dependency graph with

mvn dependency:tree

检查哪个依赖项依赖于旧的 spring 库,并排除那些已经在他的答案中发布的@alexandar-petrov。

从您正在构建的 Artifact 中排除依赖项不会对 Intellij 或任何其他 IDE 将使用的类路径产生任何影响。

关于spring - Intelli j idea调试时tomcat加载低版本spring库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56422327/

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