问题描述
我的项目在swagger2版本2.7.0上运行正常。不是spring boot(仅spring mvc) 我打算将其升级为3.0.0,但会出现插件错误。
java.lang.nosuchMethodError:org.springframework.plugin.core.pluginRegistry.getPluginFor(Ljava/lang/Object;)Ljava/util/Optional;
我的配置如下:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>
Update: As mentioned in https://github.com/springfox/springfox
Step 2 : Add @EnableOpenApi for open API (and @EnableSwagger2WebMvc or @EnableSwagger2WebFlux for older versions)
I added @EnableSwagger2WebMvc in class,Then it's asking dependency of springfox-swagger2,as this coming from :
http://springfox.github.io/springfox/javadoc/snapshot/springfox/documentation/swagger2/annotations/EnableSwagger2WebMvc.html
which is part of springfox-swagger2 dependency
Hence I am confused what to do..
can you please help cleaner approach with steps .
If I don't use @EnableSwagger2WebMvc/EnableSwagger2
Swagger is not getting loaded
解决方法
不确定是使用Spring Boot还是常规的Spring风格,但是您是否遵循此处发布的迁移说明?
https://github.com/springfox/springfox
- 删除对
springfox-swagger2
的明确依赖性 - 删除所有
@EnableSwagger2...
批注 - 添加
springfox-boot-starter
(Spring启动)或springfox-oas
(Spring MVC)依赖项 - 检查您是否不依赖于
guava
上已删除的依赖项 - 如果您使用的是
WebMvc
,但尚未使用@EnableWebMvc
注释,请添加此注释(春季启动)。