728x90

기본적으로 조져지던 Swagger는 Springfox 에서 조져지는데 이 친구들은 3.x.x 대로 올라오면서 사실상 업데이트가 제대로 맞춰지지 않았기 때문에 엄청나게 거시기 한 점이 있다.

 

 따라서 OpenAPI의 SpringDoc 를 조져주는 게 좋은데,  이 경우에도 버전에 따라서 양상이 좀 다르게 바뀐다

 

3 버전대 이전 버전에서 Spring Doc 조지기

implementation("org.springdoc:springdoc-openapi-ui:1.6.11")

 

3.2.2 버전의 경우 아래와 같이 dedencies 를 조져준다

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

 

잘 보면 의존성에 따라서 Library 가 변한 것을 알 수 있는데, 결과적으로 버전에 따른 Library 를 안맞춰주면 

Whitelabel Error Page를 감상할 수 있다.

대충 이렇게 생긴 친구인데 의존성을 안맞춰주면 2024년도에도 이렇게 똑같이 발생한다는 말이다.

 

또한 괜히 Library 는 많으면 많을 수록 좋다는 생각으로 2가지 친구를 동시에 추가시켜 줬다가는 다음과 같은 빨간맛을 볼 수 있다.

 

after Using .apis(RequestHandlerSelectors.basePackage("com.szs.columbus.controller")) // Replace with your controller package, I'm in error like this
Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway. The base url is the root of where all the swagger resources are served. For e.g. if the api is available at http://example.org/api/v2/api-docs then the base url is http://example.org/api/. Please enter the location manually:

 

그리고 추가적으로 종종 localhost 기반에서 들어가서 접속해보면 박스가 하나 뜨면서 

너새끼의 basePackage 가 잘못되었으니 수동으로 한번 꼬라박아줄래? 라고 계속 물어본다

 


번외. Springfox 너새끼는 어디까지 가능한가

추가적으로 Springfox 3.0.0에서는 Spring Boot 2.5와 2.6 에서 사용되는 것과 별개로 약간의 변화가 생기는데.

2. Remove Explicit @EnableSwagger2 Annotation

Springfox 3.0.0 and later versions with Spring Boot starters do not require the @EnableSwagger2 annotation. You can remove this annotation from your configuration class.

 

Annotation 하나를 제거해준다는 특징이 있다.

 

결론 = 그냥 어지간하면 이제는 OpenAPI 의 SpringDoc 이 답이다

 


추가적으로 application.properties 에서 path 기반하에 있는걸 다 박아주는 것도 설정할  수 있는데

 

In application.properties 

# Swagger Base
springdoc.packages-to-scan=com.szs.columbus.controller

 

이런식으로 Controller Package 하부를 죄다 박아버릴 수 있다. (이건 당연히 예전에 Springfox 에서도 지원되던 것이다.)

 

 

참조하면 좋은 글

https://sjh9708.tistory.com/169

 

[Spring Boot] Swagger API Docs 작성하기 (SpringDoc, SpringBoot 3 버전)

이전에 Spring Boot 프로젝트에 Swagger를 연동해 본 적이 있었다. 최근 Spring Boot의 지원 버전이 3점대로 올라감과 동시에, 2점대에서 Swagger 사용 목적으로 많이 사용되는 SpringFox가 안타깝게도 제대로

sjh9708.tistory.com

https://colabear754.tistory.com/99

 

[Spring Boot] Springdoc 라이브러리를 통한 Swagger 적용

목차 기본 환경 IntelliJ Ultimate 2022.3 Spring Boot 2.7.7 Kotlin 1.7.21(JDK 11) Springdoc Openapi UI 1.6.11 Springdoc은 무엇인가? 이전에 Spring Boot 프로젝트에 Swagger UI를 적용하는 포스트를 작성한 적이 있다. 해당 포

colabear754.tistory.com

 

+ Recent posts