[Spring]Swagger3.0 설치

강은서·2022년 8월 19일
0

Spring

목록 보기
11/11
post-thumbnail

Swagger 설치

  • 설치 환경
    spring-boot : 2.7.2
    swagger : 3.0.0

  • build.gradle에 의존성 추가

	implementation 'io.springfox:springfox-boot-starter:3.0.0'
	implementation 'io.springfox:springfox-swagger-ui:3.0.0'
  • SwaggerConfig 설정
@Configuration
@EnableSwagger2
@EnableAutoConfiguration
public class SwaggerConfig {

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.OAS_30)
                .useDefaultResponseMessages(false)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.example.springswagger.controller"))
                .paths(PathSelectors.any())
                .build()
                .apiInfo(apiInfo());
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Practice Swagger")
                .description("practice swagger config")
                .version("1.0")
                .build();
    }
}

Swagger 접속

http://[호스트ip]/swagger-ui/로 접속하면,다음과 같이 접속이 된다.

처음엔 http://[호스트ip]/swagger-ui.html 로 접속했는데, swagger 3.0부터는 접속 url이 바꾸었다고 한다.

오류

Failed to start bean 'documentationPluginsBootstrapper';

설치하면서 다음과 같은 오류가 발생하였다.

다음 블로그 에서 Spring boot 2.6버전 이후에 spring.mvc.pathmatch.matching-strategy 값이 ant_apth_matcher에서 path_pattern_parser로 변경되면서 발생한다고 하여, application.properties에 추가하고 서버를 재시작하였다.

  • application.properties
spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER

하지만, 나는 그래도 문제가 발생하였고, 다음 stackoverflow 글을 참고하여 application class에 @EnableWevMvc를 추가하고 오류를 해결할 수 있었다.

  • SpringApplication.java
@SpringBootApplication
@EnableWebMvc
public class SpringApplication {

	public static void main(String[] args) {
		SpringApplication.run(SpringApplication.class, args);
	}

}

0개의 댓글