본문 바로가기

STUDY/Spring

Spring Boot | Swagger2 사용 (springfox-boot-starter:3.0.0)

1. 의존성 추가

Gradle사용할 경우

dependencies {
    implementation "io.springfox:springfox-boot-starter:3.0.0"
}

Maven사용할 경우

<dependency>
  <groupId>io.springfox</groupId>
  <artifactId>springfox-boot-starter</artifactId>
  <version>3.0.0</version>
</dependency>

 

2. 설정

@EnableSwagger2어노테이션 사용하지 않아도 됨

@Configuration
public class SpringFoxConfig {
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("This is Title")
                .version("1.0")
                .description("Blah Blah")
                .license("라이센스울라불라")
                .build();
    }
}

 

원래 http://localhost/swagger-ui.html로 접속했었는데, http://localhost/swagger-ui/로 바뀌었다고 한다... 

계속 404에러 떴는데... 이게 문제였음.... 폰트 크기 63pt로 써놓지 좀...

 

출처: https://springfox.github.io/springfox/docs/current/#getting-started

 

 

 

+)공식문서

 

Springfox Reference Documentation

The Springfox suite of java libraries are all about automating the generation of machine and human readable specifications for JSON APIs written using the spring family of projects. Springfox works by examining an application, once, at runtime to infer API

springfox.github.io