반응형
레거시 프로젝트의 스프링부트 버전이 2.1.2여서 한꺼번에 올리지는 못하고 기존의 2.7.18로 업그레이드를 하는 중이였다.
하나씩 설정을 바꿔가며(application.yml 및 @ConfigurationProperties 등...변경된 점이 많았다) 오류를 잡아가던 도중에 다음과 같은 에러를 만나게 되었다. 에러의 내용을 보면 Swagger에 대해서 뭔가 잘못되었다는 것과 하필 제일 귀찮은 NPE에러를 내뿜고 있었다
Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException
여기저기 구글링을 통하여 찾아가던중 Spring Boot의 버전이 2.6 이후에 MVC Matching-strategy가 ant_path_matcher에서 path_pattern_parser로 바뀌었다는 글을 많이 보았다. 해당 부분을 추가하고나서 해결이 되겠건만 했지만 해결되지 않았다
# application.yml에 아래설정을 추가해도 해결되지 않았다
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
우선 Swagger가 문제였으니 해당 내용으로 하나하나 찾아가다보니 나와 동일한 이슈를 만나신 분이 계셨다
우선 해당 이슈는 SpringFox에서 Swagger를 업데이트 해주지 않아 발생한 이슈이고 다음과 같이 Bean을 등록하면 해결이 된다
@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));
}
아래는 Spring Fox 이슈
반응형
'개발 > Java' 카테고리의 다른 글
Spring Boot - ObjectMapper 생성시 초기 configuration (0) | 2024.04.23 |
---|