본문 바로가기

Server

Spring Boot 에 Swagger2 적용 방법

728x90

아래 주소에서 자신이 사용할 Swagger 버전을 찾는다.
https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui

이 글에서는 2.9.2 버전을 선택해서 사용한다

Gradle Dependency 에 추가한다

implementation group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2'
implementation group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2'

 

그리고 Swagger 를 설정할 클래스를 하나 만든다

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket restAPI() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.hyobin.roh"{여기에 패키지명 넣기}))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("효빈의 API")
                .version("1.0.0")
                .description("효빈의 API 입니다")
                .build();
    }
}

 

코드 작성 및 Spring Boot 실행 후
http://localhost:8080/swagger-ui.html 
접속.

동작 확인

728x90