Springfox swagger 在 Spring Boot 2.2.0 中不起作用

2024-02-22

我想将 spring boot v2.1.9 升级到 2.2.0。但升级后我遇到了一些异常,这表明 spring Fox 使用的是旧版本的 spring-plugin-core。

有没有替代解决方案或者我需要放弃 springfox 插件?

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    springfox.documentation.spring.web.plugins.DocumentationPluginsManager.createContextBuilder(DocumentationPluginsManager.java:152)

The following method did not exist:

    org.springframework.plugin.core.PluginRegistry.getPluginFor(Ljava/lang/Object;Lorg/springframework/plugin/core/Plugin;)Lorg/springframework/plugin/core/Plugin;

The method's class, org.springframework.plugin.core.PluginRegistry, is available from the following locations:

    jar:file:/C:/Users/regosa/.m2/repository/org/springframework/plugin/spring-plugin-core/2.0.0.RELEASE/spring-plugin-core-2.0.0.RELEASE.jar!/org/springframework/plugin/core/PluginRegistry.class

It was loaded from the following location:

    file:/C:/Users/regosa/.m2/repository/org/springframework/plugin/spring-plugin-core/2.0.0.RELEASE/spring-plugin-core-2.0.0.RELEASE.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of org.springframework.plugin.core.PluginRegistry

maven依赖树文件:https://drive.google.com/file/d/1gayvvVe_VsB1P2Hi2rcwRw8NdK89qtbq/view https://drive.google.com/file/d/1gayvvVe_VsB1P2Hi2rcwRw8NdK89qtbq/view

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 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.xxxxx.business.workflow</groupId>
    <artifactId>xxxxx-component-workflow-starter</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>xxxxx-component-workflow-starter</name>
    <description>xxxxx-component-workflow-starter</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>11</java.version>
        <jaxb-runtime.version>2.4.0-b180830.0438</jaxb-runtime.version>
        <spring-cloud.version>Greenwich.M1</spring-cloud.version>
       <zeebe-version>0.20.1</zeebe-version>    
        <google-guava.version>27.0.1-jre</google-guava.version>
        <xxxxx.version>1.0</xxxxx.version>
        <swagger.version>2.9.2</swagger.version>
        <jjwt.version>0.9.1</jjwt.version>
        <json.version>20180813</json.version>
        <slf4j-api.version>1.7.25</slf4j-api.version>
        <mysql.version>8.0.11</mysql.version>
        <mongo-java-driver.version>3.10.1</mongo-java-driver.version>
        <commons-io.version>2.6</commons-io.version>
        <commons-lang.version>2.6</commons-lang.version>
        <commons-pool2.version>2.5.0</commons-pool2.version>
        <redis.version>3.1.0</redis.version>
        <velocity.version>1.7</velocity.version>
        <velocity-tools.version>2.0</velocity-tools.version>
        <logstash-logback-encoder.version>5.3</logstash-logback-encoder.version>
        <httpclient.version>4.5.6</httpclient.version>
        <jaxb-runtime.version>2.4.0-b180830.0438</jaxb-runtime.version>
        <env>local</env>
    </properties>   

    <dependencies>
        <!-- Start: Spring Libraries -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.kafka</groupId>
            <artifactId>spring-kafka</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-sleuth</artifactId>
        </dependency>
        <!-- End: Spring Libraries -->

        <!-- Adding JAXB Runtime since it is not shipped with JDK 9+ -->
        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-runtime</artifactId>
            <version>${jaxb-runtime.version}</version>
        </dependency>

        <!-- Start: xxxxx Libraries -->
        <dependency>
            <groupId>com.xxxxx</groupId>
            <artifactId>xxxxx-entity</artifactId>
            <version>${xxxxx.version}</version>
        </dependency>
        <dependency>
            <groupId>com.xxxxx</groupId>
            <artifactId>xxxxx-redis</artifactId>
            <version>${xxxxx.version}</version>
        </dependency>
        <dependency>
            <groupId>com.xxxxx</groupId>
            <artifactId>xxxxx-mongo</artifactId>
            <version>${xxxxx.version}</version>
        </dependency>           
        <dependency>
            <groupId>com.xxxxx</groupId>
            <artifactId>xxxxx-util</artifactId>
            <version>${xxxxx.version}</version>
        </dependency>
        <dependency>
            <groupId>com.xxxxx.model</groupId>
            <artifactId>xxxxx-model</artifactId>
            <version>${xxxxx.version}</version>
        </dependency>
        <dependency>
            <groupId>com.xxxxx.service</groupId>
            <artifactId>xxxxx-common-service</artifactId>
            <version>${xxxxx.version}</version>
        </dependency>
        <dependency>
            <groupId>com.xxxxx.service</groupId>
            <artifactId>xxxxx-common-messaging</artifactId>
            <version>${xxxxx.version}</version>
        </dependency>   
        <dependency>
            <groupId>com.xxxxx.service</groupId>
            <artifactId>xxxxx-common-security</artifactId>
            <version>${xxxxx.version}</version>
        </dependency>           
        <!-- End: xxxxx Libraries -->

        <!--  Adding Zeebe client as part of the Spring Startup -->     
        <dependency>
            <groupId>io.zeebe</groupId>
            <artifactId>zeebe-client-java</artifactId>
            <version>${zeebe-version}</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>${google-guava.version}</version>
        </dependency>

        <!-- Logstash Log Encoder -->
        <dependency> 
            <groupId>net.logstash.logback</groupId> 
            <artifactId>logstash-logback-encoder</artifactId> 
            <version>${logstash-logback-encoder.version}</version> 
        </dependency>

        <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.version}</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.mongodb/mongo-java-driver -->
        <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>mongo-java-driver</artifactId>
            <version>${mongo-java-driver.version}</version>
        </dependency>       

        <!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>${commons-io.version}</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/commons-lang/commons-lang -->
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>${commons-lang.version}</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-pool2 -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-pool2</artifactId>
            <version>${commons-pool2.version}</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>${redis.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>${httpclient.version}</version>
        </dependency>

        <!-- Start: Swagger Libraries -->
        <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>${swagger.version}</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>${swagger.version}</version>
        </dependency>
        <!-- End: Swagger Libraries -->

        <!-- Start: Spring Boot and Security Test Libraries -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- End: Spring Boot and Security Test Libraries -->

    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <finalName>xxxxx-component-workflow-starter</finalName>
        <filters>
            <filter>${env}-build.properties</filter>
        </filters>
        <resources>
            <resource>
                <filtering>true</filtering>
                <directory>${project.basedir}/src/main/resources</directory>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <release>${java.version}</release>
                </configuration>
            </plugin>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-jar-plugin</artifactId>
              <configuration>
                <archive>
                  <manifestEntries>
                    <Automatic-Module-Name>com.xxxxx.business.workflow.component.starter</Automatic-Module-Name>
                  </manifestEntries>
                </archive>
              </configuration>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories> 
</project>

Fixed!!!

该问题的存在是因为 spring Fox 库内部依赖于 spring-plugin-core:1.2.0 但它实际上需要 spring-plugin-core:2.0.0。用于支持 Web Flux 的 swagger 库的 SNAPSHOT 版本中似乎缺少此依赖性更正。

We 只需要纠正 Maven 依赖关系如下所示,无需更改代码:

  • Maven POM 依赖关系修复
<dependency>
  <groupId>io.springfox</groupId>
  <artifactId>springfox-swagger2</artifactId>
  <version>3.0.0-SNAPSHOT</version>
  <exclusions>
    <exclusion>
      <groupId>org.springframework.plugin</groupId>
      <artifactId>spring-plugin-core</artifactId>
    </exclusion>
  </exclusions>
</dependency>
<dependency>
  <groupId>io.springfox</groupId>
  <artifactId>springfox-swagger-ui</artifactId>
  <version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
  <groupId>io.springfox</groupId>
  <artifactId>springfox-spring-webflux</artifactId>
  <version>3.0.0-SNAPSHOT</version>
  <exclusions>
    <exclusion>
      <groupId>org.springframework.plugin</groupId>
      <artifactId>spring-plugin-core</artifactId>
    </exclusion>
  </exclusions>
</dependency>
<dependency>
  <groupId>org.springframework.plugin</groupId>
  <artifactId>spring-plugin-core</artifactId>
  <version>2.0.0.RELEASE</version>
</dependency>
  • Swagger配置:(与之前相同,仅供参考)
    @Configuration
    @EnableSwagger2WebFlux
    public class SwaggerConfiguration {

        @Bean
        public Docket api(final TypeResolver typeResolver) {
            return new Docket(DocumentationType.SWAGGER_2)
                    .select()
                    .apis(RequestHandlerSelectors.any())
                    .paths(PathSelectors.any())
                    .build();
        }
    }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Springfox swagger 在 Spring Boot 2.2.0 中不起作用 的相关文章

随机推荐

  • 在 matplotlib 文本框中对齐 LaTeX 数学文本

    我正在尝试生成一个文本框 其中包含正确对齐的 LaTeX 代码行matplotlib框架 我尝试使用格式对齐方法 即 lt 11 但它似乎不适用于数学模式 这是我得到的输出 哪里的 符号should全部向右对齐 参见下面的 MWE 我怎样才
  • QT:QProgressBar显示文本

    我有一个处于选取框模式的 QProgressBar 实例 最大值 最小值 0 我现在想在进度条上添加一些文本 例如 正在加载 文档说 请注意 是否绘制文本取决于样式 目前 CDE CleanLooks Motif 和 Plastique 绘
  • iOS 应用程序中的分析 - 请求用户同意

    我正在考虑是否在我的 iOS 应用程序中包含 Google 分析 显然我想要分析数据 但我关心的是是否简单地告知用户数 据正在被收集 或者专门请求他们的同意 是否需要特定同意 或者可以通过加载页面或网站隐私政策页面简单地告知用户 苹果有关于
  • 更新 MacOS 和 Xcode 后,Xcode 8.1“未找到匹配的配置文件”

    我正在使用 TestFlight 测试我的应用程序 但更新到 MacOS 10 12 和 Xcode 8 1 后无法上传我的档案 当我存档我的应 用程序时 单击 上传到应用程序商店 选择我的开发 我收到此错误 找不到 Application
  • 整数和 int 对偶性?

    有人可以向我解释一下吗 List
  • 是否可以使用观察者来跟踪 AVAudioPlayer 对象?

    我遵循了有关如何使用 KVO 机制设置和观察者的文档http developer apple com library mac documentation Cocoa Conceptual KeyValueObserving KeyValue
  • Python PySerial.如何知道端口是否已经打开?

    我正在尝试使用 python 和 PySerial 编写一个在 Linux PC 中使用串行端口的应用程序 但在这台电脑上还有其他应用程序使用串口 在尝试使用端口之前 如何知道端口是否已被其他应用程序打开 thanks PySerial 网
  • Eslint 无法解析并以红色突出显示可选链接 (?.) 和空合并 (??) 运算符

    我正在寻找相关的 eslint 规则 babel 插件提案可选链 babel plugin proposal nullish coalescing operator 当我执行以下操作时 我的编辑器会以红色突出显示 const baz obj
  • 使用回归输出处理张量流中的大型 numpy 数组(51 个输出)

    我有一个非常大的数据集 它是一个 npy 文件 其中包含大约 1 5m 个元素 每个元素都是 150x150x3 图像 输出有 51 列 51 个输出 由于数据集无法装入内存 如何加载它并使用它来拟合模型 一种有效的方法是使用 TFReco
  • 无法在 OS X Big Sur 上编译 C++,“ld:未找到 -lgcc_s.10.4 的库”

    将 MacBook Pro 升级到 OS X 11 1 Big Sur 后 我无法使用 gcc 编译 c 程序 我将 CLion 与 CMake 结合使用 重新加载 CMake 配置时出现以下错误 ld library not found
  • 排名较高的 Trait Bound 和盒装闭包终身问题

    我正在尝试编写一个返回盒装闭包的函数 该函数可以处理对任何类型的引用 寿命 当编写特定实例时 一切正常 但是在编写泛型时 版本 我遇到了终身问题 struct Parameter lt a gt s a str fn main let cl
  • 将事件附加到控件

    如何将事件插入到 aspx cs 页面 我有一个 asp button 我希望在 aspx cs 页面中添加该按钮的事件 是怎么做的 假设你有一个这样的按钮
  • 为什么 NetBeans IDE 看不到生成的源?

    我有一个 Maven 构建的 Web 应用程序 在后端使用 JPA 2 0 JPA 提供程序是 EclipseLink 2 3 2 当我构建项目 并且部署成功运行 时 它会在目录中构建 JPA 元模型 basedir target gene
  • PhpStorm 无法解析多个数据库连接的列

    我只使用 PhpStorm 一周左右 到目前为止 在设置数据库连接后 我的所有 SQL 查询都运行良好 没有错误 当前代码实际上使用第二个数据库 一个用于用户 另一个用于特定产品 因此我也在数据库选项卡中添加了该连接 但它仍然给我一个 无法
  • OpenCV Python dlib 构建轮 (setup.py)

    我正在尝试在 Ubuntu 上安装face recognition 我不断陷入这个循环 永远持续下去 请帮忙 pip install face recognition Collecting face recognition Using ca
  • DoctrineExtensions SoftDeleteable 的配置条目:gedmo/doctrine-extensions

    我正在尝试使用softdelete的选项gedmo 学说扩展 https github com Atlantic18 DoctrineExtensions blob master doc softdeleteable md但由于某种原因当我
  • 使用 Sinatra 提供静态文件

    我有一个仅使用 HTML CSS 和 JavaScript 的一页网站 我想将应用程序部署到 Heroku 但我找不到方法 我现在正在尝试使该应用程序与 Sinatra 一起使用 application css application js
  • 单击 asp:LinkBut​​ton 时调用 JavaScript 函数

    只是想知道 是否可以在单击时调用 asp LinkBut ton 下的 JavaScript 例子 我有以下代码 我希望它在被单击时调用 JavaScript 函数 test 我怎样才能做到呢
  • ASP.Net:IE6 发出无效请求

    我有一个实时网站 其中记录了每个错误并通过电子邮件发送给我 我收到很多 填充无效且无法删除 的信息 对 WebResource axd 的请求出错 仔细一看 这个请求是错误的 这是有问题的请求 webresource axd d mgqvd
  • Springfox swagger 在 Spring Boot 2.2.0 中不起作用

    我想将 spring boot v2 1 9 升级到 2 2 0 但升级后我遇到了一些异常 这表明 spring Fox 使用的是旧版本的 spring plugin core 有没有替代解决方案或者我需要放弃 springfox 插件 A