묠니르묘묘
꾸준히 성장하는 개발자스토리
묠니르묘묘
전체 방문자
오늘
어제
  • 분류 전체보기 (188)
    • 프로그래밍 (48)
      • 디자인패턴 (4)
      • 예외,에러 (4)
      • Java (29)
      • Kotlin (3)
      • React.js (4)
      • JavaScript (2)
      • Apache Kafka (2)
    • Spring (49)
      • Spring (21)
      • Spring Cloud (3)
      • JPA (25)
    • 코딩테스트 (31)
      • 알고리즘 (5)
      • Java - 백준 (26)
      • Java - 프로그래머스 (0)
    • AWS (7)
    • 데이터베이스 (6)
    • 개발 etc (23)
    • 도서 (5)
    • 회고록 (4)
    • 데브코스-데이터엔지니어링 (15)

인기 글

최근 글

hELLO · Designed By 정상우.
묠니르묘묘

꾸준히 성장하는 개발자스토리

Swagger 3.0 documentationPluginsBootstrapper 에러 해결하기
프로그래밍/예외,에러

Swagger 3.0 documentationPluginsBootstrapper 에러 해결하기

2023. 5. 3. 13:57

🚀 에러 발생 원인

org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException

해당 에러는 SpringBoot 2.6 버전 이후 spring.mvc.pathmatch.matching-strategy 값이 ant_path_matcher에서 path_pattern_parser로 변경되면서 발생하는 오류이다.

 

따라서 아래와 같이 application.yml 또는 application.properties를 고치면 된다.

spring:
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher

 

이렇게 몇달전에 해결하여 Swagger3.0을 잘 사용하였고, 현재 다시 프로젝트를 실행해보니 똑같은 에러가 나오기 시작했다.

그래서 해당 swagger 라이브러리를 제공하고 있는 springfox의 깃허브에 들어가서 관련 이슈를 찾아보니 여러 사람들이 겪고 있던 문제여서 해결방법이 있었다.

 

🚀 해결 방법

1. application.yml을 수정한다

위에서 적었던 방법을 사용한다.

 

2. IntelliJ IDEA를 사용하고 있다면 캐시 무효화/다시시작을 한다

인텔리제이 캐시 무효화

나는 한글버전의 인텔리제이여서 캐시 무효화로 나와있지만 영어로는 Invalidate Cache/Restart 라고 되어있을 것이다.

 

3. WebMvcEndpointHandlerMapping 스프링 빈 설정하기

@Bean
public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(WebEndpointsSupplier webEndpointsSupplier, ServletEndpointsSupplier servletEndpointsSupplier,
                                                                     ControllerEndpointsSupplier controllerEndpointsSupplier, EndpointMediaTypes endpointMediaTypes,
                                                                     CorsEndpointProperties corsProperties, WebEndpointProperties webEndpointProperties, Environment environment) {
    List<ExposableEndpoint<?>> allEndpoints = new ArrayList<>();
    Collection<ExposableWebEndpoint> webEndpoints = webEndpointsSupplier.getEndpoints();
    allEndpoints.addAll(webEndpoints);
    allEndpoints.addAll(servletEndpointsSupplier.getEndpoints());
    allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints());
    String basePath = webEndpointProperties.getBasePath();
    EndpointMapping endpointMapping = new EndpointMapping(basePath);
    boolean shouldRegisterLinksMapping = this.shouldRegisterLinksMapping(webEndpointProperties, environment, basePath);
    return new WebMvcEndpointHandlerMapping(endpointMapping, webEndpoints, endpointMediaTypes, corsProperties.toCorsConfiguration(), new EndpointLinksResolver(allEndpoints, basePath), shouldRegisterLinksMapping, null);
}

private boolean shouldRegisterLinksMapping(WebEndpointProperties webEndpointProperties, Environment environment, String basePath) {
    return webEndpointProperties.getDiscovery().isEnabled()
            && (StringUtils.hasText(basePath)
            || ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT));
}

해당 코드는 SpringBoot Actuator의 WebMvcEndpointHandlerMapping 빈을 정의하는 것이다.

이 Bean은 Actuator 엔드포인트를 Spring Web MVC 요청 매핑에 등록한다.

 

이 해결 방법이 내 코드를 크게 수정하지 않고 Swagger 에러를 해결할 수 있는 방법이었다.

이 외에도 여러 해결방법들이 있었지만 이 것으로 해결되었기에 여기까지만 작성하고 이 방법들은 springfox 깃허브 이슈에서 확인하였으므로 아래 참고 URL을 보길 바란다.

 


참고

https://github.com/springfox/springfox/issues/3791

저작자표시 비영리 (새창열림)

'프로그래밍 > 예외,에러' 카테고리의 다른 글

스프링부트 실행 시 IllegalStateException 발생  (0) 2023.02.13
Java ArrayIndexOutOfBoundsException  (0) 2022.01.23
Java ConcurrentModificationException  (0) 2022.01.21
    '프로그래밍/예외,에러' 카테고리의 다른 글
    • 스프링부트 실행 시 IllegalStateException 발생
    • Java ArrayIndexOutOfBoundsException
    • Java ConcurrentModificationException
    묠니르묘묘
    묠니르묘묘

    티스토리툴바