I have a maven spring web(3.2.*) project build with target war, I want to debug it in intellij idea with tomcat(web:war exploded artifact), but the web application always failed to load,
[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)
Because in some pom dependencies, they referenced lower version spring(3.0.7), I can exclude them in the ware with maven-war-plugin(2.3):packagingExcludes, but how I can exclude them in 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 has a not easy to understand way how it resolves dependency conflicts. It's called the nearest-wins strategy, which could lead to the usage of an older version.
Try to use Maven Dependency Management in combination with the Maven Enforcer Plugin to fixate version and to fail a build if you didn't define a dependency version explicit.
The easy way would be to analyse the dependency graph with
mvn dependency:tree
check which dependency depends on the old spring library and exclude that like @alexandar-petrov already posted in his answer.
Excluding the dependency from the artifact you are building won't have any effects on the classpath that Intellij or any other IDE will use.