스프링 부트 2.2.0에서 Springfox swagger가 작동하지 않습니다.


13

스프링 부트 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

메이븐 종속성 트리 파일 : 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>

어떤 예외?
Shailesh Chandra

1
@ShaileshChandra 질문을 업데이트했습니다. 실제로 swagger는 이전 스프링 플러그인 코어 (1.2V)를 사용하지만 스프링 부트 2.2.0은 v2.0을 사용합니다.
Joyson Rego 2009 년

pom.xml을 공유 할 수 있습니까?
earandap

나는 치어 파일도 받는다는 종속성 트리 업데이트 @earandap
Joyson 레고

당신은 당신의 자신감의 설정을 공유 할 수 있습니다, 어떤 문제에 직면하지 않았다, 2.O에 봄 부팅 2.1.x의에서 내 샘플 프로젝트를 업데이트
Shailesh 찬드라에게

답변:


8

SpringFox 3.0.0-SNAPSHOT함께 사용할 수 있습니다Spring Boot 2.2.X

  • SNAPSHOT 버전이므로 공식 maven 저장소에 게시되지 않으며 jcenter-snapshots에서 가져와야합니다.
  • @EnableSwagger2제거로 변경 @EnableSwagger2WebMvc하고@EnableSwagger2WebFlux

메이븐

    <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>

저장소

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

샘플 구성

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

참고 문헌

  1. Springfox 문서

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

참고 : 이 보인다는 SpringFox것입니다 죽지 않았어 .


이것은 나를 위해 일했습니다. 잘만되면 3.0은 곧 GA에 간다!
thejavagirl

6

분명히 SpringFox버려지고 마지막 버전은 Spring Boot 2.2.X와 더 이상 호환되지 않으므로 대안을 찾아야합니다 ( 여기 Github 에보 고 된 문제 참조 ).

가능한 옵션 중 하나를 사용하는 것 OpenAPI docs입니다. 이를 위해서는 SpringFox종속성 을 제거하고 다음을 추가해야합니다.

        <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>

또한 Swagger구성 클래스 를 제거 하고 다음을 제공해야합니다.

    @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."));
    }
}

필자의 경우 노출되지 않은 JPA Rest 저장소를 제외하고 모든 것이 작동하는 것 같습니다. 이 답변을 찾으면 수정으로 업데이트합니다.

이들은 내가 이것을 고치기 위해 확인한 링크 중 일부입니다.


누가 isEnabled를 사용하고 있습니까? 왜이 구성이 필요합니까?
Kalpesh Soni

당신은 그것을 무시할 수 있습니다, 그것은 내가 이전 Swagger를 비활성화하는 데 사용했던 플래그였습니다. 코드 샘플에서 제거했습니다
Victor

아직 봄 부팅 2.2에서 나를 위해 나던 작품은, 자신감-자원 webjars에서 제공하지 않는 것 같다 stackoverflow.com/questions/59293380/...
Kalpesh SONI

OpenApi는 모 놀리 식 앱의 대체물로 작동하지만 MSOA에서 스프링 폭스의 유연성을 대체 할 수는 없습니다
Simas Joneliunas

왜 SpringFox가 포기되었다고 말합니까? 꽤 살아있다. 조금 뒤쳐져 있습니다. 참조 springfox.github.io/springfox
스테판 Hüttemann

5

결정된!!!

스프링 폭스 라이브러리는 내부적으로 spring-plugin-core : 1.2.0에 의존하지만 문제는 실제로 spring-plugin-core : 2.0.0이 필요하기 때문에 문제가 있습니다. 웹 종속성을 지원하기위한 SNAPSHOT 버전의 swagger 라이브러리에서이 종속성 수정이 누락 된 것 같습니다.

우리는 아래 주어진 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>
  • 스와 거 구성 : (참조 용으로 만 사용)
    @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();
        }
    }

나를 위해 일했다, 많이 감사합니다 !!!
Prakash Hari Sharma

0

hateos 의존성을 제거하지만 swagger 만 추가하십시오. 효과가있다

// hateos는 Spring 2.1.X 및 그 이상의 컴파일 그룹에 대한 수정 사항이 업데이트되지 않았으므로 현재 스와 거만 사용합니다. 'io.springfox', 이름 : 'springfox-swagger-ui', 버전 : '2.9.2' 컴파일 그룹 : 'io.springfox', 이름 : 'springfox-swagger2', 버전 : '2.9.2'


0

spring-boot 2.2.2.RELEASE를 사용하고 있으며 spring-coreswagger에 문제가 없습니다 . 수입은 범인이었다

spring-boot-starter-data-rest
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.