Swagger 적용시 발생했던 Error

최태양 (choittttt)·2024년 3월 2일

사용버전

Spring : 2.7.x

implementation "io.springfox:springfox-boot-starter:3.0.0"
implementation "io.springfox:springfox-swagger-ui:3.0.0"

1. 발생한 오류

org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper';

해결방법

SpringBoot 2.6 버전 이후
spring.mvc.pathmatch.matching-strategy 의 기본 값이 path_pattern_parser로 변경됨

따라서 기존 값으로 ant_path_matcher로 변경

application.properties
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
application.yml
spring:
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher

2. 발생한 오류

swagger 적용 후 index.html로 접속했을때 발생한 에러였다. Spring Security를 적용한 상태였는데 swagger 관련 url이 예외처리 되지 않아서 발생한 오류다.

해결방법

기존에는 swagger-ui/index.html 만 허용을 했었다.

.antMatchers("/swagger-ui/**").permitAll()

찾아보니 swagger 관련 url을 더 추가해주었다.

.antMatchers("/swagger-ui/**", "/api/v2/**", "/health",
                "/swagger-resources/**", "/webjars/**", 
                     "/v2/api-docs").permitAll()
profile
Better Than Yesterday

0개의 댓글