我有一个用目标 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/