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

标签 spring maven tomcat intellij-idea war

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

相关文章:

search - Nutch 搜索始终返回 0 个结果

java - Spring中实例DAI与Singleton Bean的交互

spring - 基于 HTTPS/SSL 的 AWS ELB 背后的 Zuul

在 nexus 中找不到 maven-metadata.xml

maven - Bamboo - SonarQube 多模块 maven 项目跳过子模块

java - 失败 - 上下文路径/j2eeapplication 中的应用程序无法启动

java - 生成新索引时 SOLR master 中偶尔出现 SocketTimeoutException

spring JMS 错误处理程序未调用

spring - 通过 Jhipster 中的 UI 使用 Elasticsearch 对现有数据库 MySQL 执行搜索操作

java.lang.RuntimeException : Error starting org. neo4j.kernel.EmbeddedGraphDatabase