programing

Spring Fox를 사용한 Spring Boot Swagger 구현 'documentation Plugins Bootstrapper' 시작 실패

linuxpc 2023. 7. 10. 22:07
반응형

Spring Fox를 사용한 Spring Boot Swagger 구현 'documentation Plugins Bootstrapper' 시작 실패

나는 스프링 부츠 프로젝트에서 스웨거 구현을 위해 스프링폭스 항아리를 사용하고 있습니다. 그라들 의존성은 다음과 같습니다.

dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter-webflux', version: '2.1.3.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-configuration-processor', version: '2.1.3.RELEASE'
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '2.1.3.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.1.3.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-rest', version: '2.1.3.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.1.3.RELEASE'
implementation 'org.flywaydb:flyway-core'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'org.hsqldb:hsqldb'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'io.projectreactor:reactor-test'
compile group: 'org.postgresql', name: 'postgresql', version: '42.2.5'
testImplementation 'junit:junit:4.12'
testImplementation 'org.hamcrest:hamcrest-library:1.3'
compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.1'
    compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.1'
    //compile group: 'io.springfox', name: 'springfox-data-rest', version: '2.9.1'
    // Unit testing dependencies
    // Set this dependency if you want to use Hamcrest matching

}

Swagger 구성 파일:

package com.myapp.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@EnableSwagger2
@Configuration
public class SwaggerConfig {

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2).select()
                .apis(RequestHandlerSelectors.basePackage("com.mypackage.rtp.controller"))
                .paths(PathSelectors.regex("/.*")).build().apiInfo(apiEndPointsInfo());
    }

    private ApiInfo apiEndPointsInfo() {
        return new ApiInfoBuilder().title("Spring Boot REST API").description("Employee Management REST API")
                .license("Apache 2.0").licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html").version("1.0.0")
                .build();
    }

}

스프링 부트를 실행하는 동안 다음 경고가 표시됩니다.

WARN  [main] org.springframework.context.support.AbstractApplicationContext: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NoSuchMethodError: org.springframework.plugin.core.PluginRegistry.getPluginFor(Ljava/lang/Object;Lorg/springframework/plugin/core/Plugin;)Lorg/springframework/plugin/core/Plugin;

서버가 다음과 함께 종료됩니다.

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

    org.springframework.data.rest.core.support.UnwrappingRepositoryInvokerFactory.<init>(UnwrappingRepositoryInvokerFactory.java:57)

The following method did not exist:

    org.springframework.plugin.core.PluginRegistry.of(Ljava/util/List;)Lorg/springframework/plugin/core/PluginRegistry;

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

    jar:file:/C:/Users/vgoswami/.gradle/caches/modules-2/files-2.1/org.springframework.plugin/spring-plugin-core/1.2.0.RELEASE/f380e7760032e7d929184f8ad8a33716b75c0657/spring-plugin-core-1.2.0.RELEASE.jar!/org/springframework/plugin/core/PluginRegistry.class

It was loaded from the following location:

    file:/C:/Users/vgoswami/.gradle/caches/modules-2/files-2.1/org.springframework.plugin/spring-plugin-core/1.2.0.RELEASE/f380e7760032e7d929184f8ad8a33716b75c0657/spring-plugin-core-1.2.0.RELEASE.jar


Action:

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

도움을 주신다면 대단히 감사하겠습니다...

나는 같은 문제를 가지고 있었고, 스프링 코어를 가지고 오랜 시간 장난치고, 허세 등을 부렸다, 나는 아래 의존성이 실제 범인이라는 것을 발견했습니다.

spring-boot-starter-data-rest

이것을 제거하기만 하면 됩니다.

springfox:
  documentation:
    auto-startup: false

내 일은 잘되요~~

참조: https://springfox.github.io/springfox/docs/snapshot/ #configuring-messages

버전 3.0.0-SNAPshot을 통해 스웨거 종속성 추가

<repositories>
  <repository>
    <id>jcenter-snapshots</id>
    <name>jcenter</name>
    <url>http://oss.jfrog.org/artifactory/oss-snapshot-local/</url>
  </repository>
</repositories>
...
<dependencies>
  <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>
</dependencies>

사용하다@EnableSwagger2WebMvc대신@EnableSwagger2그리고.@Import({SpringDataRestConfiguration.class})주석을 입력합니다.

설명서: https://springfox.github.io/springfox/docs/snapshot/

이 종속성 추가

<dependency>
            <groupId>org.springframework.plugin</groupId>
            <artifactId>spring-plugin-core</artifactId>
            <version>1.2.0.RELEASE</version>
        </dependency>

언급URL : https://stackoverflow.com/questions/56092034/spring-boot-swagger-implementation-using-spring-fox-failed-to-start-bean-docume

반응형