SpringBoot集成Swagger3.0使用

SpringBoot集成Swagger3.0使用

一、pom文件导入依赖

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

二、启动文件添加@EnableOpenApi

@EnableOpenApi
@SpringBootApplication
public class DemoApplication {
 
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
 
}

三、启动访问路径:http://localhost:9001/swagger-ui/index.html

备注:端口不一定要和我一样

注意点

这次更新,移除了原来默认的swagger页面路径:http://host/context-path/swagger-ui.html,

新增了两个可访问路径:

  1. http://host/context-path/swagger-ui/index.html
  2. http://host/context-path/swagger-ui/

通过调整日志级别,还可以看到新版本的swagger文档接口也有新增,除了以前老版本的文档接口/v2/api-docs之外,还多了一个新版本的/v3/api-docs接口。

原文地址:https://www.cnblogs.com/zhanqing/p/swagger3.html