Spring/Kotlin

[Kotlin + SpringBoot + JPA] Swagger 설정 및 동작

For_HW 2021. 7. 18. 16:13

Swagger 사용 설정

저는 본격적인 개발을 시작하기 전에, Swagger를 사용 설정을 해주었습니다.

 

1. 우선 필요한 해당 의존성을 추가해주었습니다.

//swagger 추가.
    implementation("io.springfox:springfox-swagger2:2.9.2")
    implementation("io.springfox:springfox-swagger-ui:2.9.2")

 

2. @Configuration을 추가해주었습니다.

@Configuration
@EnableSwagger2
class SwaggerConfig {

    @Bean
    fun api(): Docket {
        return Docket(DocumentationType.SWAGGER_2)
            .select()
            .apis(RequestHandlerSelectors.basePackage("hw.boardkotlin"))
            .paths(PathSelectors.regex("/.*"))
            .build()
            .apiInfo(apiInfo())
    }

    private fun apiInfo(): ApiInfo {
        return ApiInfoBuilder().apply {
            title("BrotherOne Board API")
            description("API Endpoint for serving file")
            contact(Contact("Brotherone", "https://github.com/Hyeongwon-up", "leehwdatabase@gmail.com"))
        }.build()
    }
}

 

3. http://localhost:8080/swagger-ui.html 통해 확인할 수 있습니다.

 

'Spring/Kotlin'의 다른글

  • 현재글 [Kotlin + SpringBoot + JPA] Swagger 설정 및 동작

관련글