Backend/Spring Boot
원본 글 보기

[Spring Boot] 2.7.1에서 Swagger 3.0.0 에러 해결

swagger를 적용하는 방법 :

https://blog.naver.com/ghdalswl77/222794931667

저번에 SpringBoot 2.6.x 버전에서도 이런저런 충돌이 있었는데 이번에도ㅎㅎ

SpringBoot 2.7.1 환경에서

swagger 3.0.0 버전을 사용하려고 했는데

뭔가 충돌이 나는지 다음과 같은 에러나 났다.

org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181)

고생하다가 알아낸 해결책을 정리해둔다.

1. SwaggerConfig 클래스(swagger 설정한 class)에 WebMvcConfiguationSupport 를 상속

2. 새로운 경로를 잡아준다



public class SwaggerConfig extends WebMvcConfigurationSupport {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/swagger-ui/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/swagger-ui/3.52.5/");
}

이렇게 하고 다시,

서버홈경로/swagger-ui/index.html 으로 접속하면 잘 될것이다.

swagger-ui3.0의 jar파일 내부 구조를 보고 설정했다.