Dependency 추가
implementation 'io.springfox:springfox-boot-starter:3.0.0'
implementation 'io.springfox:springfox-swagger-ui:3.0.0'
Application.properties 추가
spring.mvc.pathmatch.matching-strategy=ANT_PATH_MATCHER
java> project > config파일에 SwaggerConfig.class파일 만들기
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())//basepackage("project도 가능")
.paths(PathSelectors.any())
.build().apiInfo(apiInfo());
}
private ApiInfo apiInfo() {
String description = "Welcome Log Company";
return new ApiInfoBuilder()
.title("SWAGGER TEST")
.description(description)
.version("1.0")
.build();
}
}
Swagger API 문서접속
http://localhost:8080/swagger-ui/index.html