當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
[Swagger2]SpringBoot集成Swagger
生活随笔
收集整理的這篇文章主要介紹了
[Swagger2]SpringBoot集成Swagger
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
SpringBoot集成Swagger
引入依賴
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 --> <dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger2</artifactId><version>2.9.2</version> </dependency> <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui --> <dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger-ui</artifactId><version>2.9.2</version> </dependency>編寫HelloController,測試確保運行成功!
package com.xxxx.swagger2.controller;import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;@RestController public class HelloController {@RequestMapping(value = "/hello")public String hello(){return "hello";}}要使用Swagger,我們需要編寫一個配置類-SwaggerConfig來配置 Swagger
@Configuration //配置類 @EnableSwagger2// 開啟Swagger2的自動配置 public class SwaggerConfig { }訪問測試 :http://localhost:8080/swagger-ui.html ,可以看到swagger的界面;
總結
以上是生活随笔為你收集整理的[Swagger2]SpringBoot集成Swagger的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [Spring5]AOP底层原理
- 下一篇: gradle idea java ssm