dependency μΆκ°
λ¨Όμ μ€μ¨κ±° λνλμλ₯Ό μΆκ°νλ€. build.gradle νμΌμ λΌμ΄λΈλ¬λ¦¬λ₯Ό μΆκ°ν΄μ€λ€.
νμν λΌμ΄λΈλ¬λ¦¬μ λνλμλ νμ λ§ν¬μμ μ½κ² μ°Ύμ μ μλ€.
https://mvnrepository.com/artifact/io.springfox/springfox-swagger2/2.9.2
Maven Repository: io.springfox » springfox-swagger2 » 2.9.2
mvnrepository.com
...
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-aop'
implementation 'org.springframework.kafka:spring-kafka'
implementation 'org.projectlombok:lombok'
// swagger
implementation group: 'io.springfox', name: 'springfox-swagger2', version: '2.6.1'
implementation group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.6.1'
testImplementation 'org.springframework.kafka:spring-kafka-test'
}
...
// swagger λ°μ λ μ€μ μ λ ₯ν΄μ£Όκ³ , Load Gradle Changesλ₯Ό ν΄μ€λ€.
swagger-uiλ μ€μ¨κ±°κ° μμ±νλ API λ¬Έμλ₯Ό μ¬μ©μ λνλ°©μμΌλ‘ λ μ½κ² λ§λ€μ΄ μ£Όλ λ΄μ₯ μ루μ μ΄λ€.
SwaggerConfig.java νμΌ μμ±
package com.kiwius.kafka.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
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.basePackage("com.kiwius.kafka")).paths(PathSelectors.any())
.build();
}
}
- @Configuration μ΄λ
Έν
μ΄μ
μ€νλ§ IOC Containerμκ² ν΄λΉ ν΄λμ€λ₯Ό Bean κ΅¬μ± ν΄λμ€μμ μλ €μ€λ€. - @Bean μ΄λ
Έν
μ΄μ
@Component μ΄λ Έν μ΄μ λ λ€ IOC Containerμ Beanμ λ±λ‘νλλ‘ νλ λ©νλ°μ΄ν°λ₯Ό κΈ°μ νλ μ΄λ Έν μ΄μ μ΄λ€.
λ€λ₯Έ μ μ @Beanμ κ°λ°μκ° μ§μ μ μ΄κ° λΆκ°λ₯ν μΈλΆ λΌμ΄λΈλ¬λ¦¬ λ±μ BeanμΌλ‘ λ§λ€ λ μ¬μ©νλ€.
λ°λλ‘ @Componentλ κ°λ°μκ° μ§μ μμ±ν ν΄λμ€λ₯Ό BeanμΌλ‘ λ±λ‘ν λ μ¬μ©νλ€. - ν΄λΉ config νμΌμ ν΅ν΄ basePackage νμμ Rest APIκ° Swaggerλ₯Ό ν΅ν΄ κ΄λ¦¬λλ€.
swagger-ui.html μ μ
- http://localhost:8080/swagger-ui.htmlμ μ μν΄ νμΈνλ€.
'ΰ¨βββ Web βββΰ§ > β SpringBoot' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[Gradle] implementation, runtimeOnly, compileOnly μ°¨μ΄μ (0) | 2022.06.26 |
---|---|
[SpringBoot] νλ‘μ νΈ μμ± (0) | 2021.03.29 |
[Spring] μμ‘΄μ± μ£Όμ (DI) (0) | 2021.03.24 |