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文件里面,這樣才能起效,否則可能會沒效果。
