這篇文章主要介紹了SpringBoot集成Swagger如何添加maven依賴,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
SpringBoot集成Swagger 添加maven依賴
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.9.2</version> </dependency>
要求:jdk 1.8 + 否則swagger2無法運行 要使用Swagger,我們需要編寫一個配置類-SwaggerConfig來配置 Swagger
package com.yf.exam.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.ArrayList;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
//配置了swagger的Docket 的 bean 實例
@Bean
public Docket docket(){
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo());
}
//配置 swagger 信息 = apiInfo
private ApiInfo apiInfo(){
//作者信息
Contact contact = new Contact("瀟七", "https://www.xhost.vip/", "2278023068@qq.com");
return new ApiInfo("API文檔",
"接口信息",
"v1.0",
contact,
"Apache 2.0",
"http://www.apache.org/licenses/LICENSE-2.0",
new ArrayList()
);
}
}訪問測試 :http://localhost:8080/swagger-ui.html ,可以看到swagger的界面;
-

knife4j
官網參考地址:knife4j
knife4j是為Java MVC框架集成Swagger生成Api文檔的增強解決方案(在非Java項目中也提供了前端UI的增強解決方案),前身是swagger-bootstrap-ui,取名knife4j是希望她能像一把匕首一樣小巧,輕量,并且功能強悍!
簡潔
基于左右菜單式的布局方式,是更符合國人的操作習慣吧.文檔更清晰…
個性化配置
個性化配置項,支持接口地址、接口description屬性、UI增強等個性化配置功能…
增強
接口排序、Swagger資源保護、導出Markdown、參數緩存眾多強大功能.
SpringBoot集成Knife4j 添加maven依賴
<dependency> <groupId>com.github.xiaoymin</groupId> <artifactId>knife4j-spring-boot-starter</artifactId> <!--在引用時請在maven中央倉庫搜索最新版本號--> <version>2.0.4</version> </dependency>
-訪問測試 :http://localhost:8080/doc.html ,可以看到knife4j的界面;

離線文檔導出
Knife4j提供導出4種格式的離線文檔(Html\Markdown\Word\Pdf)
感謝你能夠認真閱讀完這篇文章,希望小編分享的“SpringBoot集成Swagger如何添加maven依賴”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關注億速云行業資訊頻道,更多相關知識等著你來學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。