Search
🕣

Spring Actuator, Swagger 의존성 충돌

태그
spring boot
모니터링을 위해 Actuator 의존성을 추가하고 실행시켜보니 자세한 원인이 나오긴 커녕 nullpointerexception 에러가 발생
이슈 발생 원인
springfox는 Spring MVC가 Ant-based path matcher를 기본값으로 하여 경로를 찾는ㄷ[ 스프링부트 2.6.x 버전부터 PathPattern-based matcher로 변경해서 발생하는 이슈
Swagger는 모든 endpoint에 대해 documentation 해주는 역할이고
Actuator는 health, info, metrics, shutdown 등 몇 endpoint를 직접 생성해서 노출시켜주는 역할로 이 두 의존성이 충돌되어 발생
해결 방안
1.
Spring Boot 버전을 2.5.x 이하로 변경
2.
Ant-based path matcher으로 변경 & WebMvcEndpointHandlerMapping 설정
2번 해결방안 코드
@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); }
Java
복사
참고 블로그