spring - NoSuchMethodError:org.springframework.plugin.core.PluginRegistry.getPluginOrDefaultFor
问题描述
一切都很好,即使使用 Swagger 但在新构建项目无法编译后突然抛出
Caused by: org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NoSuchMethodError: org.springframework.plugin.core.PluginRegistry.getPluginOrDefaultFor(Ljava/lang/Object;Lorg/springframework/plugin/core/Plugin;)Lorg/springframework/plugin/core/Plugin;
我已经尝试过此链接的解决方案: https ://github.com/springfox/springfox/issues/2932 但是编译错误仍然存在。
我正在附加 pom.xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.geborskimateusz.microservices.composite.movie</groupId>
<artifactId>movie-composite-service</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>movie-composite-service</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<swagger.version>3.0.0-SNAPSHOT</swagger.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.geborskimateusz</groupId>
<artifactId>api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.geborskimateusz</groupId>
<artifactId>util</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-spring-webflux</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-kafka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-test-support</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Greenwich.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<repositories>
<repository>
<id>jcenter-snapshots</id>
<name>jcenter</name>
<url>http://oss.jfrog.org/artifactory/oss-snapshot-local/</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
任何想法,这与招摇版本有关吗?
解决方案
当使用给定的方法签名编译一段代码,但在运行时发现另一个代码时,会发生此错误。
这通常发生在编译时使用的依赖项版本与运行时实际提供给程序的依赖项之间存在差异时。
我们刚刚和一位同事也遇到了这个错误,我们通过简单地将 spring boot 版本更改为 2.2.2 来修复它。
不确定到底发生了什么,但鉴于版本是 SNAPSHOT,一个疯狂的猜测是 springfox 的最后一个工作版本(为您和我们工作)是使用低于 2.2.2 的 Spring boot 版本编译的。该引导版本具有不同的 getPluginOrDefaultFor 方法签名(或者该方法可能根本不存在)。
你的程序看不出有什么不同,因为 swagger lib 的 API 没有改变,所以看起来没有任何改变,突然出现错误。但是实际的 swagger lib 的底层实现依赖于 Spring Boot 2.2.2 中的某些方法,因为 Boot 的版本是 2.1.0,所以在您的设置中找不到该方法,这会在期望找到的内容与实际找到的内容之间产生冲突做。
无论如何,只需将您的 Boot 升级到 2.2.2 即可修复它;如果你不需要 webflux 模块,可能会将 spring-fox 降级到 2.9.2 - 但似乎你需要(没有机会尝试,因为在我们的例子中,我们确实需要 springfox webflux 依赖项)
推荐阅读
- c# - 从 C# 运行 tabcmd 命令时 Process.Start() 未完成
- objective-c - 如何从代码在 SceneKit 中设置基于物理的渲染?
- jquery - 无法使用 jQuery.toggle() 以编程方式切换(仅关闭)Highchart 的默认上下文菜单
- go - 如何在 Go 中自动生成 Avro 模式?
- java - 提取 .jar 时如何播放音频文件?
- c# - 在 ASP.NET 中使用 MySqlCommand 的 MySQL 语法错误
- r - 在 r 中使用 as.numeric() 时值会发生变化
- c# - 从 C# 中的 SQL Server 参数获取字节数组
- unit-testing - Karma Jasmine:相同的函数名称,两个不同的源文件
- api - HomeBridge eWeLink WebSocketClient:错误'0'(错误:意外的服务器响应(200))