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,
新增了兩個可訪問路徑:
- http://host/context-path/swagger-ui/index.html
- http://host/context-path/swagger-ui/
通過調整日志級別,還可以看到新版本的swagger文檔接口也有新增,除了以前老版本的文檔接口/v2/api-docs之外,還多了一個新版本的/v3/api-docs接口。