본문 바로가기

프로그래밍/SpringBoot

Spring Boot 2.7.9에서 Swagger 사용하기 (swagger-ui.html 404 문제)

스프링 부트 버전에 따라 스웨거 사용에 차이가 있다...

강의는 2.3 이하 버전이어서 2.7.x 인 나는 강의보고 따라가려니 안되는 부분이 너무 많아서 재작성한다.

 

pom.xml

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-boot-starter</artifactId>
    <version>3.0.0</version>
</dependency>

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>3.0.0</version>
</dependency>

 

application.yml

logging:
  level:
    root: info
    org.springframework: info

spring:
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher
  messages:
    basename: messages

 

SwaggerConfig.class

package com.example.restfulwebservice.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
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);
    }
}

 

 

 

http://localhost:8088/v2/api-docs

http://localhost:8088/swagger-ui/index.html

 

강의에서는 swagger-ui.html 이었지만,, 버전에 따라 바뀐 내용이 너무 많아 힘들다

 

 

 

포트번호는 각자 지정한 번호로 변경해서 사용하면 된다.

 

 

나도 html로 문서 볼 수 있다!