Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
Tags
- 윤성우 열혈자료구조
- 윤성우의 열혈 자료구조
- datastructure
- 이것이 자바다
- Stack
- C programming
- Serialization
- JSON
- coding test
- 혼자 공부하는 C언어
- buffer
- 메모리구조
- list 컬렉션
- Algorithm
- stream
- R
- 알기쉬운 알고리즘
- s
- Selection Sorting
- 이스케이프 문자
- C 언어 코딩 도장
- insertion sort
- Graph
Archives
- Today
- Total
Engineering Note
[Spring] Spring boot에 Swagger 적용하기(Maven) 본문
Swagger란?
Swagger는 Web API 문서화를 위한 도구이다. 서버와 클라이언트 사이에서 어떠한 방식으로 데이터를 주고 받을지에 대한 명세가 필요한데, 이러한 내용이 담긴 문서이다.
Swagger의 기능
- API 설계
- API 개발
- API 테스트
- API 모킹 및 시각화하기
- API 모니터링
- API 관리
Spring boot에 Swagger 설정
패키지 적용(Maven)
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>설정
클래스 생성
SaggerConfig라는 클래스를 생성하고 아래와 같이 작성해준다.
package com.example.demo.config;
import com.example.demo.repository.ArticleRepository;
import com.example.demo.service.ArticleService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
@Configuration
public class SpringConfig {
private final ArticleRepository articleRepository;
public SpringConfig(ArticleRepository articleRepository){
this.articleRepository = articleRepository;
}
@Bean
public ArticleService articleService(){ return new ArticleService(articleRepository);}
}
Annotation
Springboot 메인 클래스 파일에 다음과 같이 @EnableSwagger2 어노테이션을 추가해준다. 그리고 localhost:8080/swagger-ui/index.html로 접속하면 Swagger UI를 적용하는 페이지를 볼 수 있다.
@SpringBootApplication
@EnableSwagger2
public class ServerApplication {
}
참고 자료:
https://velog.io/@seho100/Spring-boot%EC%97%90-Swagger-%EC%A0%81%EC%9A%A9%ED%95%98%EA%B8%B0Maven
'Server > Spring' 카테고리의 다른 글
Comments
