Swagger Springfox tidak bekerja di spring boot 2.2.0

13

Saya ingin memutakhirkan spring boot v2.1.9 ke 2.2.0. Tetapi setelah upgrade saya mendapatkan beberapa pengecualian, yang mengatakan spring fox menggunakan versi yang lebih lama dari spring-plugin-core.

Apakah ada solusi alternatif untuk ini atau apakah saya harus melepaskan plugin 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

file pohon ketergantungan maven: 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>
Joyson Rego
sumber
pengecualian apa?
Shailesh Chandra
1
@ShaileshChandra Saya memperbarui pertanyaan. Sebenarnya kesombongan menggunakan spring-plugin-core (1.2 V) lama tetapi spring boot 2.2.0 menggunakan v2.0.
Joyson Rego
dapatkah Anda membagikan pom.xml Anda?
earandap
@earandap Saya memperbarui file pom dan juga maven dependency tree
Joyson Rego
baru saja memperbarui proyek sampel saya dari spring boot 2.1.x ke 2.o, tidak menghadapi masalah apa pun, dapatkah Anda membagikan konfigurasi kesombongan Anda
Shailesh Chandra

Jawaban:

8

Anda bisa menggunakannya SpringFox 3.0.0-SNAPSHOTbersamaSpring Boot 2.2.X

  • Karena ini adalah versi SNAPSHOT, itu tidak diterbitkan dalam repositori resmi pakar dan perlu ditarik dari jcenter-snapshots
  • @EnableSwagger2dihapus dan diubah menjadi @EnableSwagger2WebMvcdan@EnableSwagger2WebFlux

Maven

    <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>3.0.0-SNAPSHOT</version>
        </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-data-rest</artifactId>
            <version>3.0.0-SNAPSHOT</version>
    </dependency>

Gudang

    <repositories>
        <repository>
            <id>jcenter-snapshots</id>
            <name>jcenter</name>
            <url>http://oss.jfrog.org/artifactory/oss-snapshot-local/</url>
        </repository>
    </repositories>

Konfigurasi Sampel

@EnableSwagger2WebMvc
@Import(SpringDataRestConfiguration.class)
public class SpringFoxConfig {
    //...
}

Referensi

  1. Dokumen Springfox

  2. https://www.baeldung.com/swagger-2-documentation-for-spring-rest-api

Catatan: Sepertinya SpringFoxini tidak mati .

Sandeep Suresh
sumber
Ini berhasil untuk saya. Semoga 3.0 segera masuk ke GA!
thejavagirl
6

Rupanya, sejak SpringFoxditinggalkan dan versi terakhirnya tidak kompatibel dengan Spring Boot 2.2.X, Anda harus mencari alternatif (lihat masalah yang dilaporkan di Github di sini ).

Salah satu opsi yang memungkinkan adalah menggunakan OpenAPI docs. Untuk itu Anda perlu menghapus SpringFoxdependensi dan menambahkan ini:

        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-ui</artifactId>
            <version>1.2.15</version>
        </dependency>
         <dependency>
              <groupId>org.springdoc</groupId>
              <artifactId>springdoc-openapi-webmvc-core</artifactId>
              <version>1.2.15</version>
        </dependency>

Anda juga harus menghapus Swaggerkelas konfigurasi dan menyediakan ini:

    @Configuration
    public class OpenApiConfig {

    @Bean
    public OpenAPI customOpenAPI() {
        return new OpenAPI()
                .components(new Components())
                .info(new Info().title("Contact Application API").description(
                        "This is a sample Spring Boot RESTful service using springdoc-openapi and OpenAPI 3."));
    }
}

Dalam kasus saya, semuanya tampaknya berfungsi dengan pengecualian repositori JPA Rest yang tidak terekspos. Saya akan memperbarui jawaban ini dengan perbaikan, jika saya menemukannya.

Ini adalah beberapa tautan yang saya periksa untuk memperbaikinya:

Pemenang
sumber
siapa yang menggunakan isEnabled, mengapa kita perlu konfigurasi ini?
Kalpesh Soni
Anda dapat mengabaikannya, itu adalah bendera yang saya gunakan untuk menonaktifkan mantan Swagger. Saya telah menghapus dari contoh kode
Victor
masih tidak bekerja untuk saya di boot musim semi 2.2, tampaknya sumber daya angkuh tidak dilayani dari webjars stackoverflow.com/questions/59293380/…
Kalpesh Soni
OpenApi berfungsi sebagai pengganti aplikasi monolitik, tetapi tidak dapat menggantikan fleksibilitas springfox di MSOA
Simas Joneliunas
Mengapa Anda mengatakan bahwa SpringFox ditinggalkan? Cukup hidup. Hanya sedikit tertinggal. Lihat springfox.github.io/springfox
Stefan Hüttemann
5

Tetap!!!

Masalahnya ada karena pustaka spring fox secara internal bergantung pada pegas-plugin-inti: 1.2.0 tetapi sebenarnya membutuhkan pegas-plugin-inti: 2.0.0. Koreksi ketergantungan ini tampaknya tidak ada dalam versi SNAPSHOT dari pustaka swagger untuk mendukung fluks web.

Kami hanya perlu memperbaiki dependensi Maven seperti yang diberikan di bawah ini dan tidak diperlukan perubahan kode:

  • Ketergantungan POM Maven diperbaiki
<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>
  • Konfigurasi Swagger: (Sama seperti sebelumnya hanya untuk referensi)
    @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();
        }
    }
nitin-techyplanet
sumber
Bekerja untuk saya, terima kasih banyak !!!
Prakash Hari Sharma
0

Hapus dependensi kebencian, tetapi hanya menambahkan kesombongan. Berhasil

// Hanya menggunakan sombong seperti sekarang, karena kebencian tidak memperbarui perbaikan untuk Spring 2.1.X dan grup kompilasi di atas: 'io.springfox', nama: 'springfox-swagger-ui', versi: '2.9.2' kompilasi grup: 'io.springfox', nama: 'springfox-swagger2', versi: '2.9.2'

KiniTap
sumber
0

Saya menggunakan spring-boot 2.2.2.RELEASE dan tidak ada masalah dengan spring-core dan swagger . Impor di bawah ini adalah pelakunya

spring-boot-starter-data-rest
vicky
sumber