查找冲突
当启动时有类似如下错误时,说明有依赖的jar包冲突,一般在错误里面会指明xxx.jar是冲突的jar包。
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call the method xxx; but it does not exist. Its class, xxx, is available from the following locations:
jar:file:/C:/Users/xxx/.m2/xxx.jar!/com/xxx/xxx.class
jar:file:/C:/Users/xxx/.m2/xxx.jar!/com/xxx/xxx.class
It was loaded from the following location:
xxx
Action:
Correct the classpath of your application so that it contains a single, compatible version of xxx
在idea中打开pom文件(如果有多个module,需要逐个pom打开排查),右击鼠标,选择Diagrams>show dependencies,会出现所有jar包的依赖关系图,如果出现红色连线,说明有冲突
解决冲突
在jar包依赖关系图中ctrl+f查找上面提示的冲突jar包名称,查看下方依赖它的jar包,在pom的dependency坐标中逐个移除该冲突jar包
<dependency>
<groupId>com.sample</groupId>
<artifactId>sample-artifact</artifactId>
<version>1.0.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>com.conflict</groupId>
<artifactId>conflict-jar</artifactId>
</exclusion>
</exclusions>
</dependency>