日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

简化Swagger使用的自制Starter:spring-boot-starter-swagger,欢迎使用和吐槽

發布時間:2024/7/5 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 简化Swagger使用的自制Starter:spring-boot-starter-swagger,欢迎使用和吐槽 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

項目簡介

該項目主要利用Spring Boot的自動化配置特性來實現快速的將swagger2引入spring boot應用來生成API文檔,簡化原生使用swagger2的整合代碼。

GitHub:https://github.com/dyc87112/spring-boot-starter-swagger
碼云:http://git.oschina.net/didispace/spring-boot-starter-swagger
博客:http://blog.didispace.com

小工具一枚,歡迎使用和Star支持,如使用過程中碰到問題,可以提出Issue,我會盡力完善該Starter

版本基礎

  • Spring Boot:1.5.x
  • Swagger:2.7.x

如何使用

在該項目的幫助下,我們的Spring Boot可以輕松的引入swagger2,主需要做下面兩個步驟:

  • 在pom.xml中引入依賴:
<dependency>
<groupId>com.didispace</groupId>
<artifactId>spring-boot-starter-swagger</artifactId>
<version>1.1.0.RELEASE</version>
</dependency>
  • 在應用主類中增加@EnableSwagger2Doc注解
@EnableSwagger2Doc
@SpringBootApplication
public class Bootstrap {

public static void main(String[] args) {
SpringApplication.run(Bootstrap.class, args);
}

}

默認情況下就能產生所有當前Spring MVC加載的請求映射文檔。

參數配置

更細致的配置內容參考如下:

配置示例

swagger.title=spring-boot-starter-swagger
swagger.description=Starter for swagger 2.x
swagger.version=1.1.0.RELEASE
swagger.license=Apache License, Version 2.0
swagger.licenseUrl=https://www.apache.org/licenses/LICENSE-2.0.html
swagger.termsOfServiceUrl=https://github.com/dyc87112/spring-boot-starter-swagger
swagger.contact.name=程序猿DD
swagger.contact.url=http://blog.didispace.com
swagger.contact.email=dyc87112@qq.com
swagger.base-package=com.didispace
swagger.base-path=/**
swagger.exclude-path=/error, /ops/**

配置說明

  • swagger.title=標題
  • swagger.description=描述
  • swagger.version=版本
  • swagger.license=許可證
  • swagger.licenseUrl=許可證URL
  • swagger.termsOfServiceUrl=服務條款URL
  • swagger.contact.name=維護人
  • swagger.contact.url=維護人URL
  • swagger.contact.email=維護人email
  • swagger.base-package=swagger掃描的基礎包,默認:全掃描
  • swagger.base-path=需要處理的基礎URL規則,默認:/**
  • swagger.exclude-path=需要排除的URL規則,默認:空

Path規則說明

swagger.base-path和swagger.exclude-path使用ANT規則配置。

我們可以使用swagger.base-path來指定所有需要生成文檔的請求路徑基礎規則,然后再利用swagger.exclude-path來剔除部分我們不需要的。

比如,通常我們可以這樣設置:

management.context-path=/ops

swagger.base-path=/**
swagger.exclude-path=/ops/**, /error

上面的設置將解析所有除了/ops/開始以及spring boot自帶/error請求路徑。

其中,exclude-path可以配合management.context-path=/ops設置的spring boot actuator的context-path來排除所有監控端點。


總結

以上是生活随笔為你收集整理的简化Swagger使用的自制Starter:spring-boot-starter-swagger,欢迎使用和吐槽的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。