springboot整合swagger2依赖冲突问题解决思路
实验环境1.swagger版本<dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger2</artifactId><version>2.9.2</version></dependency><depende
实验环境
1.swagger版本
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
列出问题:
Error starting ApplicationContext. To display the conditions report re-run your application with ‘debug’ enabled.
2021-07-11 09:09:39.075 ERROR 11656 — [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
APPLICATION FAILED TO START
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.hateoas.server.core.DelegatingLinkRelationProvider.<init>(DelegatingLinkRelationProvider.java:36)
The following method did not exist:
'org.springframework.plugin.core.PluginRegistry org.springframework.plugin.core.PluginRegistry.of(org.springframework.plugin.core.Plugin[])'
The method’s class, org.springframework.plugin.core.PluginRegistry, is available from the following locations:
jar:file:/D:/Environment/apache-maven-3.6.1/maven-repo/org/springframework/plugin/spring-plugin-core/1.2.0.RELEASE/spring-plugin-core-1.2.0.RELEASE.jar!/org/springframework/plugin/core/PluginRegistry.class
The class hierarchy was loaded from the following locations:
org.springframework.plugin.core.PluginRegistry: file:/D:/Environment/apache-maven-3.6.1/maven-repo/org/springframework/plugin/spring-plugin-core/1.2.0.RELEASE/spring-plugin-core-1.2.0.RELEASE.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.springframework.plugin.core.PluginRegistry
Process finished with exit code 0
大致意思就是jar包冲突,导入swagger依赖是默认会加载spring-plugin-core的jar包,它的版本是1.2.0,如下图:
重点: 不要因为报错提示The following method did not exist 就直接断定swagger自带的包不存在该方法,而在pom文件中强行修改spring-plugin-core的版本,应当先确定在当前项目中确实不存在该方法对应的jar并且依赖没有冲突,否则只会加深依赖之间的冲突 。
接下来我们便开始寻找与它冲突的jar包:
查找问题
首先查看依赖关系,找到如图的按钮,show Dependencies Dragrams 快捷键Ctrl+Alt+Shift+U
打开后如下图所示
找到红线两端的节点,双击即可跳入到对应的位置,找到对应的位置就可以进行排除,在这里我定位到了Spring Data Rest的依赖
在此处排除该依赖后,检查依赖关系图中是否还有红线(代表依赖冲突),直至全部排出后重启项目即可测试成功!
更多推荐
所有评论(0)