본문 바로가기
개발공부/개발하다_발견함

Spring boot 3.x에 Swagger 연결하기

by 맙소사 2024. 3. 12.

 

1. 스웨거를 쓰려면 springfox-swagger-ui와 springfox-swagger2로 의존성 추가를 해줘야 한다.

https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui/3.0.0

https://mvnrepository.com/artifact/io.springfox/springfox-swagger2/3.0.0

 

나는 Gradle을 사용중이라 아래처럼 build.gradle에 갖다붙여넣었다.

 

그리고 스웨거 config를 만들고 어쩌꾸 저쩌구 다 했는데 ...

스프링 3.x 에서는 스웨거를 이전 버전과 다른 방법으로 사용한다고 한다 ... 

https://stackoverflow.com/questions/74614369/how-to-run-swagger-3-on-spring-boot-3

 

How to run Swagger 3 on Spring Boot 3

Using a fresh Spring Initialzr with Java17 and Spring Boot 3.0.0, and an extra addition to the pom.xml for Springfox Swagger 3, I can't for the life of me get Swagger pages to work. Instead, I get ...

stackoverflow.com

 

공식문서는 이쪽에서 확인하면 될 것 같다. https://springdoc.org/

이건 데모버전 https://demos.springdoc.org/demo-spring-boot-3-webmvc/swagger-ui/index.html

 

일단 스프링 3.x 이상 프로젝트에서 스웨거를 연결하려면 레포지토리에서 springdoc을 가져다가 의존성 추가를 해주면 된다. 이전 스케쥴러도 그렇고 프로젝트가 점점 최신버전으로 넘어올수록 한 줄로 해결되는 정말 좋은 세상 ... 

 

https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-starter-webmvc-ui

implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'

build.gradle

 

그리고 별다른 config 파일은 만들지 않은 상태로 프로젝트를 구동하여 /swagger-ui/index.html 경로로 접속하면

 

이렇게 화면이 뜨게 된다.

 

config 설정관련해서는 https://colabear754.tistory.com/99 이쪽 블로그를 참고해서 만들었다.

이런 기본 설정같은건 다들 공식문서에서 알아낸후에 쓰는걸까 정말 대단하다

댓글