1. 报错背景介绍
笔者由于黑鸭子扫描结果需要,对本组的项目进行springboot版本进行升级,由于之前项目所用版本较低,为1.5.3,需要升级到2.2.x,结果出现如下错误:
1 Description: 2 3 An attempt was made to call a method that does not exist. The attempt was made from the following location: 4 5 org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration.backendIdConverterRegistry(RepositoryRestMvcConfiguration.java:721) 6 7 The following method did not exist: 8 9 org.springframework.plugin.core.PluginRegistry.of(Ljava/util/List;)Lorg/springframework/plugin/core/PluginRegistry; 10 11 The method's class, org.springframework.plugin.core.PluginRegistry, is available from the following locations: 12 13 jar:file:/C:/Users/1/.m2/repository/org/springframework/plugin/spring-plugin-core/1.2.0.RELEASE/spring-plugin-core-1.2.0.RELEASE.jar!/org/springframework/plugin/core/PluginRegistry.class 14 15 It was loaded from the following location: 16 17 file:/C:/Users/1/.m2/repository/org/springframework/plugin/spring-plugin-core/1.2.0.RELEASE/spring-plugin-core-1.2.0.RELEASE.jar 18 19 20 Action: 21 22 Correct the classpath of your application so that it contains a single, compatible version of org.springframework.plugin.core.PluginRegistry
2. 解决方案:
从报错信息
1 org.springframework.plugin.core.PluginRegistry.of(Ljava/util/List;)Lorg/springframework/plugin/core/PluginRegistry;
可知 ,spring-plugin-core是1.2.0版本,但是在这个版本里面是没有上述方法。通过查看maven仓库-https://mvnrepository.com/,发现这个jar包就几个版本,不是在低版本就是在高版本中。查验之后发现这个方法是在2.0.0版本中存在的。所以目标明确,去掉1.2.0,引入2.0.0版本,maven依赖如下:
1)修改原pom文件,去掉swagger中引入的1.2.0版本
1 <dependency> 2 <groupId>io.springfox</groupId> 3 <artifactId>springfox-swagger2</artifactId> 4 <version>2.9.2</version> 5 <exclusions> 6 <exclusion> 7 <groupId>org.springframework.plugin</groupId> 8 <artifactId>spring-plugin-core</artifactId> 9 </exclusion> 10 <exclusion> 11 <groupId>org.springframework.plugin</groupId> 12 <artifactId>spring-plugin-metadata</artifactId> 13 </exclusion> 14 </exclusions> 15 </dependency> 16 <dependency> 17 <groupId>io.springfox</groupId> 18 <artifactId>springfox-swagger-ui</artifactId> 19 <version>2.9.2</version>
2)新引入spring-plugin-core的2.0.0版本
<!-- https://mvnrepository.com/artifact/org.springframework.plugin/spring-plugin-core --> <dependency> <groupId>org.springframework.plugin</groupId> <artifactId>spring-plugin-core</artifactId> <version>2.0.0.RELEASE</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework.plugin/spring-plugin-metadata --> <dependency> <groupId>org.springframework.plugin</groupId> <artifactId>spring-plugin-metadata</artifactId> <version>2.0.0.RELEASE</version> </dependency>
但是注意一点,这个jar需要提前引入,所以最好要放在父POM文件里面,这样才能起效,否则可能会没效果。