微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法在Spring REST API中将swagger2版本从2.7.0升级到3.00常规Spring不能进行sprint引导

如何解决无法在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

  1. 删除对springfox-swagger2的明确依赖性
  2. 删除所有@EnableSwagger2...批注
  3. 添加springfox-boot-starter(Spring启动)或springfox-oas(Spring MVC)依赖项
  4. 检查您是否不依赖于guava上已删除的依赖项
  5. 如果您使用的是WebMvc,但尚未使用@EnableWebMvc注释,请添加此注释(春季启动)。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。