无法在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注释,请添加此注释(春季启动)。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...