Swagger , http://localhost:8080/swagger-ui/ 404오류
Swagger란 개발한 Rest API를 편하게 문서화 해주고 이를 통해 관리 및 제 3의 사용자가 편리하게 API를 호출해보고 테스트 할 수 있는 프로젝트이다.
Spring Boot에서는 간단하게 springfox-boot-starter를 gradle dependencies에 추가 함으로 사용할 수 있다.
외부에 노출되면 안되는 곳에 사용할 떈 주의 해야 한다.
스프링부트에서 사용한 Swagger dependency
https://mvnrepository.com/artifact/io.springfox/springfox-boot-starter/3.0.0
http://localhost:8080/swagger-ui/ << 계속 404 오류가 났다
조금 찾아보니 Spring Boot 3.0 이상 버전부터는 Springfox가 호환되지 않는다고 한다. Spring Boot 3.0부터는 Jakarta EE로 전환되었는데, Springfox는 여전히 Java EE에 의존하고 있어서 Jakarta EE와 호환되지 않기 때문
Springfox를 대체할 수 있는 Swagger 통합 방법으로는 Springdoc OpenAPI를 사용하는 것이 일반적이다.
springdoc-openapi는 Spring Boot 3.0 이상과 호환되며, OpenAPI 3.0 스펙을 지원하며 Spring Boot와 더 나은 호환성을 제공하고, 쉽게 API 문서를 생성할 수 있다고 한다.
그래서 Springfox 대신 Springdoc을 사용하기로 하였다.
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'
//implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.7.0'
//implementation "io.springfox:springfox-boot-starter:3.0.0"
좀 더 찾아보니 스프링부트 3버전 이전에는 springdoc-openapi-ui를 추가해야, 스프링부트 3버전 이후에는 springdoc-openapi-starter-webmvc-ui를 추가해야 정상적으로 스웨거 UI를 사용할 수 있다고 한다.
http://localhost:8080/swagger-ui/index.html# 로 시도하니 성공
https://github.com/springfox/springfox/issues/3360
404 when for snapshot version of springfox-swagger-ui 3.0.0-SNAPSHOT · Issue #3360 · springfox/springfox
Hello I am getting a 404 while access the swagger UI ... What's the problem How Can I resolve issue?
github.com
도움을 많이 받은 티스토리