[DEV] 기록

[SpringBoot] Failed to start bean documentationPluginsBootstrapper

꾸준함. 2022. 8. 31. 23:18

개요

SpringBoot에 actuator를 연동한 뒤 실행하였더니 아래와 같은 오류 메시지가 발생했습니다.

org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; 
nested exception is java.lang.NullPointerException: 
Cannot invoke "org.springframework.web.servlet.mvc.condition.PatternsRequestCondition.getPatterns()" because "this.condition" is null

 

원인

SpringFox 측에서 업데이트를 진행하지 않아 SpringBoot 2.6.0 이상 버전에 대해서는 위와 같은 에러가 발생합니다.

 

해결 방법

해결방법은 크게 두 가지가 있고 두 방법 모두 아래의 설정이 application.properties 혹은 application.yml에 적용되어 있어야 합니다.

spring:
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher

 

1. SpringBoot 버전을 2.5.X 이하로 다운 그레이드

SpringBoot 2.6.0 버전 이상에서만 발생하는 문제이기 때문에 SpringBoot 버전을 2.5.X 이하로 다운 그레이드 할 경우 해결이 됩니다.

 

2. 버전 변경 없이 Config 추가

버전을 변경할 수 없는 경우 아래의 코드를 Config에 추가해줄 경우 정상적으로 실행되는 것을 확인할 수 있습니다.


import org.springframework.boot.actuate.autoconfigure.endpoint.web.CorsEndpointProperties;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementPortType;
import org.springframework.boot.actuate.endpoint.ExposableEndpoint;
import org.springframework.boot.actuate.endpoint.web.*;
import org.springframework.boot.actuate.endpoint.web.annotation.ControllerEndpointsSupplier;
import org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpointsSupplier;
import org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping;
@Configuration
@EnableSwagger2
@Import(BeanValidatorPluginsConfiguration.class)
public class SwaggerConfig {
// 중략
@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));
}
// 중략
}
view raw .java hosted with ❤ by GitHub

 

참고

https://stackoverflow.com/questions/70695150/how-to-befriend-spring-boot-2-6-x-with-actuator-dependency-and-swagger-starter-3

 

How to befriend Spring Boot 2.6.X with Actuator dependency and Swagger Starter 3.0.0

I saw this issue: Springboot 2.6.0 / Spring fox 3 - Failed to start bean 'documentationPluginsBootstrapper' Top answer say to put configuration property like that spring.mvc.pathmatch.match...

stackoverflow.com

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

 

Spring 5.3/Spring Boot 2.4 support · Issue #3462 · springfox/springfox

If you enable the new PathPatternParser (https://spring.io/blog/2020/06/30/url-matching-with-pathpattern-in-spring-mvc), springfox fails with an NPE Details org.springframework.context.ApplicationC...

github.com

https://www.inflearn.com/questions/439959

 

actuator status: 404 - 인프런 | 질문 & 답변

spring : 2.6.x swagger 3.0.x actuator : 2.6.x   사용 중인데  http://localhost:8080/actuator 실행시 404 에러가 생깁니다. - 질문 & 답변 | 인프런...

www.inflearn.com

 

반응형