build.gradle 에 의존성 추가
//https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui
implementation group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2'
implementation group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2'
swaggerConfig util package에 추가 (위치 상관없음)
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket restAPI() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.example.todolist"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("todoList Spring Boot REST API")
.version("1.0.0")
.description("TodoList의 swagger api 입니다.")
.build();
}
}
application.properties 에 추가
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
접속방법
localhost:8080/swagger-ui.html
접속