230422 TIL #66 Swagger API

김춘복·2023년 4월 22일
0

TIL : Today I Learned

목록 보기
66/494

230422 Today I Learned

실전 프로젝트 4주차. 오늘은 피드백받은 내용을 고쳤다. 캐싱 전략에 있어서 수동캐싱은 위험하니 자동화가 되도록 로직을 바꿨다. 이 내용은 다음에 정리해보고, 오늘은 swagger api에 대해 알아봤다.


Swagger API 3 사용법

  1. build.gradle에 dependencies 추가
//    swagger
    implementation 'io.springfox:springfox-boot-starter:3.0.0'
  1. 에러가 나면 application.poperties에 아래 내용 추가
spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER
  1. Configuration 생성
@Configuration
public class SwaggerConfiguration {

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.OAS_30)
                .select()
                .apis(RequestHandlerSelectors.basePackage("적용하고자하는패키지명"))
                .paths(PathSelectors.any()) // /api같이 주소 설정 가능
                .build()
                .apiInfo(apiInfo());
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Practice Swagger")
                .description("practice swagger config")
                .version("1.0")
                .build();
    }
}
  1. 실행 후 Swagger3은 아래 주소로 접속
    http://localhost:8080/swagger-ui/index.html
profile
꾸준히 성장하기 위해 매일 log를 남깁니다!

0개의 댓글