java - 无法在 Spring REST API 中将 swagger2 版本从 2.7.0 升级到 3.00(常规 Spring 不是 sprint 启动)
问题描述
我的项目在 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 boot) 或springfox-oas
(Spring MVC) 依赖项 - 检查您是否不依赖已删除的依赖项
guava
- 如果您正在使用
WebMvc
但尚未使用@EnableWebMvc
注解,请添加此注解(Spring boot)。
推荐阅读
- java - 从用户输入中停止 SourceDataLine
- node.js - 带有 React 应用程序的 Dockerfile 不能与“create-react-app”一起使用。RUN 部分中的命令
- javascript - *Chainable* Javascript 方法为数组的每个项目做一些事情
- python - python中的seaborn数据框问题到groupby和count
- angular - ngx-mqtt 通过 webapp 连接到 SSL/TLS mosquitto 代理
- php - 如何通过 PHP SOAP 访问 SharePoint 中的列表项内容?
- javascript - 如何按日期过滤我的对象数组?
- javascript - Find the first same number in the same index on different for loops
- css - 如何更改 Bulma 的默认样式?
- java - 从数组列表中取出 xPos 和 YPos 值