SpringBoot之如何集成SpringDoc最詳細文檔

文章目錄

  • 一、概念解釋
    • 1、OpenAPI
    • 2、Swagger
    • 3、Springfox
    • 4、Springdoc
    • 5. 關系與區別
  • 二、SpringDoc基本使用
    • 1、導包
    • 2、正常編寫代碼,不需要任何注解
    • 3、運行后訪問下面的鏈接即可
  • 三、SpringDoc進階使用
    • 1、配置文檔信息
    • 2、配置文檔分組
    • 3、springdoc的配置參數
      • **1. 基礎配置**
        • **API 文檔路徑-springdoc.api-docs.path**
        • **Swagger UI 路徑-springdoc.swagger-ui.path**
        • **是否啟用 API 文檔-springdoc.api-docs.enabled**
        • **是否啟用 Swagger UI-springdoc.swagger-ui.enabled**
      • **2. 全局元信息-info**
        • **應用標題-springdoc.info.title**
        • **應用描述-springdoc.info.description**
        • **版本號-pringdoc.info.version**
        • **聯系人信息-springdoc.info.contact**
        • **許可信息-pringdoc.info.license**
      • **3. 分組與模塊化**
        • **分組支持-springdoc.group-configs**
        • **掃描包范圍-springdoc.packages-to-scan**
        • **排除特定路徑-springdoc.paths-to-exclude**
      • **4. 安全配置**
        • **全局安全方案**
        • **全局安全要求**
      • **5. 自定義行為**
        • **緩存控制**
        • **排序規則**
        • **服務器地址-pringdoc.servers**
      • **6. 高級配置**
        • **自定義 OpenAPI 對象**
        • **自定義 Swagger UI**
      • **7. 總結**
    • 4、SpringDoc注解
      • **1. 核心注解**
        • **@Tag**
      • **2. 方法級別注解**
        • **@Operation**
        • **@ApiResponse 和 @ApiResponses**
      • **3. 參數相關注解**
        • **@Parameter**
        • **@Parameters**
      • **4. 實體模型相關注解**
        • **@Schema**
      • **5. 其他注解**
        • **@Hidden**
      • **6. 配置相關注解(不常用)**
        • **@OpenAPIDefinition**
      • **7. 總結**
  • 四、在實際項目上如何使用
    • 1、導包
    • 2、寫配置類
      • 1)、配置實體類
      • 2)、配置類
    • 3、編寫配置參數

系列文章:
springboot-swagger詳解
springboot-優美的Knife4j文檔-Swagger進化
Spring Cloud Gateway 網關整合 Knife4j
SpringBoot之如何集成SpringDoc最詳細文檔

一、概念解釋

Swagger和Springdoc是兩個常用的工具,用于生成和維護API文檔,特別是針對基于REST的Web服務。它們有效地提升了API的可讀性和可維護性,幫助開發者、產品經理和其他利益相關者更好地理解和使用所提供的API。

談到API文檔,那就繞不開大名鼎鼎的Swagger,但是你是否還聽說過:OpenAPI,Springfox,Springdoc?你第一次看到這些腦瓜子是不是嗡嗡的?

1、OpenAPI

OpenApi 就像 JDBC 一樣,制定了各種各樣的規范,而 Swagger 和 SpringDoc 則類似于各種各樣的數據庫驅動,是具體的實現

  • 定義 :OpenAPI 是一個開放標準,用于描述 RESTful API 的接口規范。它最初由 Swagger 項目發展而來,后來成為獨立的標準(目前由 OpenAPI Initiative 維護)。

  • 版本 :

    • OpenAPI 2.0 :基于 Swagger 2.0 規范。
    • OpenAPI 3.0+ :是更新的版本,引入了許多新特性(如增強的請求體描述、組件復用等)。
  • 作用 :提供一種標準化的方式來描述 API 的結構、路徑、參數、響應等內容,便于開發者和工具生成文檔、測試接口。

2、Swagger

它是SmartBear這個公司的一個開源項目,里面提供了一系列工具,包括著名的 swagger-ui。
swagger是早于OpenApi的,某一天swagger將自己的API設計貢獻給了OpenApi,然后由其標準化了。

  • 定義 :Swagger 是一組圍繞 OpenAPI 標準構建的工具集,包括代碼生成器、UI 展示工具等。
  • 版本 :
    • Swagger 2.x :基于 OpenAPI 2.0,是最廣泛使用的版本之一。
    • Swagger 3.x :基于 OpenAPI 3.0+,支持更復雜的 API 描述功能。
  • 工具 :
    • Swagger UI :為 OpenAPI 文檔提供交互式界面,方便開發者測試 API。
    • Swagger Codegen :根據 OpenAPI 文檔生成客戶端代碼或服務器端框架代碼。

3、Springfox

是Spring生態的一個開源庫,是Swagger與OpenApi規范的具體實現。我們使用它就可以在spring中生成API文檔。以前基本上是行業標準,目前最新版本可以支持 Swagger2, Swagger3 以及 OpenAPI3 三種格式。但是其從 2020年7月14號就不再更新了,不支持springboot3,所以業界都在不斷的轉向我們今天要談論的另一個庫Springdoc,新項目就不要用了。

  • 定義 :Springfox 是一個專門為 Spring 框架設計的庫,用于自動生成基于 Swagger/OpenAPI 的 API 文檔。
  • 特點 :
    • 支持 Spring MVC 和 Spring Boot。
    • 主要基于 Swagger 2.x 和 OpenAPI 2.0 。
    • 通過注解(如 @Api、@ApiOperation 等)來描述 API。
  • 局限性 :
    • 對 OpenAPI 3.0 的支持較弱(盡管有實驗性支持,但不夠完善)。
    • 在 Spring Boot 2.6 及更高版本中,由于兼容性問題(如路徑匹配策略的變化),Springfox 的使用變得復雜甚至不可行。

4、Springdoc

算是后起之秀,帶著繼任Springfox的使命而來。其支持OpenApi規范,支持Springboot3,我們的新項目都應該使用這個。

  • 定義 :Springdoc 是一個現代化的開源庫,專為 Spring Boot 應用程序設計,用于自動生成基于 OpenAPI 3.0+ 的 API 文檔。
  • 特點 :
    • 原生支持 OpenAPI 3.0+ ,并提供對 Spring Boot 2.6+ 的良好兼容性。
    • 使用標準的 OpenAPI 注解(如 @Operation、@Parameter 等),而不是 Swagger 特有的注解。
    • 提供內置的 Swagger UI,方便開發者快速查看和測試 API。
  • 優勢 :
    • 更輕量、更易配置。
    • 更好的性能和兼容性。
    • 社區活躍,更新頻繁。

SpringDoc 支持:

  • OpenAPI 3
  • Spring-boot,全版本都支持。
  • JSR-303 中提供的一些注解,例如 @NotNull、@Min、@Max 以及 @Size 等。
  • Swagger-ui:SpringDoc 提供的接口 JSON 也可以通過 Swagger-ui 展示出來。
  • OAuth 2

5. 關系與區別

特性SpringfoxSpringdocSwaggerOpenAPI
主要用途自動生成 API 文檔自動生成 API 文檔工具集,用于生成文檔和測試 APIAPI 描述標準
支持的規范Swagger 2.x / OpenAPI 2.0OpenAPI 3.0+Swagger 2.x / Swagger 3.xOpenAPI 2.0 / OpenAPI 3.0+
Spring Boot 兼容性較差(尤其是 2.6+ 版本)良好不直接相關不直接相關
注解使用 Swagger 特定注解(如 @Api使用 OpenAPI 標準注解(如 @Operation使用 Swagger 特定注解定義了標準注解
工具支持提供 Swagger UI提供 Swagger UI提供 Swagger UI 和 Codegen無直接工具支持,需依賴實現(如 Swagger)
社區活躍度逐漸減少

二、SpringDoc基本使用

我們可以在springboot中使用SpringDoc來生成API文檔,詳情可以參考官網,下面我們來簡單的實踐一下。

1、導包

在springboot中使用springdoc起步非常容易,只需要引入其starter即可

<dependency><groupId>org.springdoc</groupId><artifactId>springdoc-openapi-ui</artifactId><version>1.7.0</version> <!-- 版本可替換 -->
</dependency>

2、正常編寫代碼,不需要任何注解

在這里插入圖片描述

3、運行后訪問下面的鏈接即可

http://server:port/context-path/swagger-ui.html

例如:

http://localhost:9204/swagger-ui.html
在這里插入圖片描述

三、SpringDoc進階使用

雖然上邊配置的SpringDoc很好用,但是對比swagger我們就知道,缺少了很多信息,當然springdoc的集成不可能就這點東西,不然也沒有這篇文章了。

1、配置文檔信息

得益于springboot的強大,我們只需添加一個依賴就可以使用API文檔了,但是使用的都是默認值,我們當然也希望對其進行各種自定義的配置

創建一個OpenAPI 的bean,配置文檔名稱等信息

package com.wenge.business.config;import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;/*** Swagger 文檔配置** @author wkl*/
@Configuration
public class SpringDocAutoConfiguration {@Beanpublic OpenAPI openApi() {return new OpenAPI().info(new Info().title("這是標題").description("這是備注").version("這是版本").license(new License().name("這是許可證").url("這是許可證鏈接")).contact(new Contact().name("這是作者").url("這是作者鏈接").email("這是作者email")));}
}

在這里插入圖片描述

2、配置文檔分組

用來配置分組的,假如你有多類controller一類以/tacticsInfo為前綴分組,一類以/admin為前綴,就可以將其配置為兩個分組。很多時候我們只有一個分組,所以就不需要下面的配置。

    @Beanpublic GroupedOpenApi publicApi() {return GroupedOpenApi.builder().group("tacticsInfo").pathsToMatch("/tacticsInfo/**")//以/tacticsInfo開頭的的api都進這個分組.build();}@Beanpublic GroupedOpenApi otherApi() {return GroupedOpenApi.builder().group("other").pathsToMatch("/admin/**")//以/tacticsInfo開頭的的api都進這個分組.build();}//    @Bean
//    public GroupedOpenApi otherApi() {
//        return GroupedOpenApi.builder()
//                .group("other")
//                .pathsToMatch("/**/**")//這樣配置,那就是所有的api都進這個分組
//                .build();
//    }

可以通過右上角的下拉框選擇要展示的group。
在這里插入圖片描述

3、springdoc的配置參數

1. 基礎配置

API 文檔路徑-springdoc.api-docs.path
  • springdoc.api-docs.path
    • 作用:指定 OpenAPI JSON 文檔的訪問路徑。
    • 默認值/v3/api-docs
    • 示例
      springdoc.api-docs.path=/openapi
      
Swagger UI 路徑-springdoc.swagger-ui.path
  • springdoc.swagger-ui.path
    • 作用:指定 Swagger UI 的訪問路徑。
    • 默認值/swagger-ui.html
    • 示例
      springdoc.swagger-ui.path=/docs
      
是否啟用 API 文檔-springdoc.api-docs.enabled
  • springdoc.api-docs.enabled
    • 作用:啟用或禁用 OpenAPI 文檔生成功能。
    • 默認值true
    • 示例
      springdoc.api-docs.enabled=false
      
是否啟用 Swagger UI-springdoc.swagger-ui.enabled
  • springdoc.swagger-ui.enabled
    • 作用:啟用或禁用 Swagger UI。
    • 默認值true
    • 示例
      springdoc.swagger-ui.enabled=false
      

2. 全局元信息-info

應用標題-springdoc.info.title
  • springdoc.info.title
    • 作用:設置 API 文檔的標題。
    • 默認值:空
    • 示例
      springdoc.info.title=用戶管理系統
      
應用描述-springdoc.info.description
  • springdoc.info.description
    • 作用:設置 API 文檔的描述信息。
    • 默認值:空
    • 示例
      springdoc.info.description=用戶管理相關的 API 文檔
      
版本號-pringdoc.info.version
  • springdoc.info.version
    • 作用:設置 API 文檔的版本號。
    • 默認值:空
    • 示例
      springdoc.info.version=1.0.0
      
聯系人信息-springdoc.info.contact
  • springdoc.info.contact.name
  • springdoc.info.contact.email
  • springdoc.info.contact.url
    • 作用:設置文檔的聯系人信息(姓名、郵箱、URL)。
    • 默認值:空
    • 示例
      springdoc.info.contact.name=John Doe
      springdoc.info.contact.email=john.doe@example.com
      springdoc.info.contact.url=http://example.com
      
許可信息-pringdoc.info.license
  • springdoc.info.license.name
  • springdoc.info.license.url
    • 作用:設置文檔的許可證信息(名稱、URL)。
    • 默認值:空
    • 示例
      springdoc.info.license.name=Apache 2.0
      springdoc.info.license.url=https://www.apache.org/licenses/LICENSE-2.0
      

3. 分組與模塊化

分組支持-springdoc.group-configs
  • springdoc.group-configs
    • 作用:為不同的控制器或包生成獨立的 API 文檔分組。
    • 示例
      springdoc.group-configs[0].group=user-api
      springdoc.group-configs[0].packages-to-scan=com.example.user
      springdoc.group-configs[1].group=order-api
      springdoc.group-configs[1].packages-to-scan=com.example.order
      
掃描包范圍-springdoc.packages-to-scan
  • springdoc.packages-to-scan
    • 作用:指定需要掃描的包范圍,用于生成 API 文檔。
    • 默認值:當前應用程序的所有包。
    • 示例
      springdoc.packages-to-scan=com.example.api
      
排除特定路徑-springdoc.paths-to-exclude
  • springdoc.paths-to-exclude
    • 作用:排除某些路徑,不將其包含在生成的 API 文檔中。
    • 默認值:無
    • 示例
      springdoc.paths-to-exclude=/admin/**
      

4. 安全配置

全局安全方案
  • springdoc.api-docs.security-schemes
    • 作用:定義全局的安全方案(如 OAuth2、API Key 等)。
    • 示例
      springdoc.api-docs.security-schemes[0].name=ApiKeyAuth
      springdoc.api-docs.security-schemes[0].type=apiKey
      springdoc.api-docs.security-schemes[0].in=header
      
全局安全要求
  • springdoc.api-docs.security-requirements
    • 作用:定義全局的安全要求。
    • 示例
      springdoc.api-docs.security-requirements[0]=ApiKeyAuth
      

5. 自定義行為

緩存控制
  • springdoc.cache.disabled
    • 作用:禁用 API 文檔的緩存。
    • 默認值false
    • 示例
      springdoc.cache.disabled=true
      
排序規則
  • springdoc.default-flat-param-object
    • 作用:是否將參數對象展平為單個參數。
    • 默認值false
    • 示例
      springdoc.default-flat-param-object=true
      
服務器地址-pringdoc.servers
  • springdoc.servers
    • 作用:定義 API 的服務器地址列表。
    • 示例
      springdoc.servers[0].url=http://localhost:8080
      springdoc.servers[0].description=本地開發環境
      springdoc.servers[1].url=https://api.example.com
      springdoc.servers[1].description=生產環境
      

6. 高級配置

自定義 OpenAPI 對象
  • 作用:通過 Java 配置類自定義 OpenAPI 對象。
  • 示例
    @Bean
    public OpenAPI customOpenAPI() {return new OpenAPI().info(new Info().title("用戶管理系統").version("1.0").description("用戶管理相關的 API 文檔")).addServersItem(new Server().url("http://localhost:8080").description("本地開發環境"));
    }
    
自定義 Swagger UI
  • 作用:通過 Java 配置類自定義 Swagger UI 行為。
  • 示例
    @Bean
    public SwaggerUiConfigProperties swaggerUiConfig() {SwaggerUiConfigProperties config = new SwaggerUiConfigProperties();config.setPath("/custom-docs");return config;
    }
    

7. 總結

以下是 springdoc 配置參數的分類總結:

類別參數作用
基礎配置springdoc.api-docs.path, springdoc.swagger-ui.path, springdoc.api-docs.enabled配置 API 文檔路徑、Swagger UI 路徑及啟用狀態。
全局元信息springdoc.info.title, springdoc.info.description, springdoc.info.version設置 API 文檔的標題、描述、版本等基本信息。
分組與模塊化springdoc.group-configs, springdoc.packages-to-scan, springdoc.paths-to-exclude支持分組、限制掃描范圍、排除特定路徑。
安全配置springdoc.api-docs.security-schemes, springdoc.api-docs.security-requirements定義全局安全方案和要求。
自定義行為springdoc.cache.disabled, springdoc.default-flat-param-object, springdoc.servers控制緩存、參數對象展平、服務器地址等高級功能。
高級配置自定義 OpenAPI 對象、Swagger UI 配置通過代碼方式實現更靈活的定制。

4、SpringDoc注解

1. 核心注解

@Tag
  • 作用:為控制器或方法分組,便于組織和分類 API。

  • 常用屬性

    • name:標簽名稱。
    • description:標簽描述信息。
  • 示例

      @Tag(name = "策略庫接口",description = "這是策略庫的所有接口")@RestController@RequestMapping("/tacticsInfo")public class TacticsInfoController extends BaseController{// ...}
    

在這里插入圖片描述


2. 方法級別注解

@Operation
  • 作用:描述一個 API 方法的功能。
  • 常用屬性
    • summary:方法的簡短描述。
    • description:方法的詳細描述。
    • responses:定義可能的響應結果。
    • deprecated:標記方法是否已廢棄。
  • 示例
      @Operation(summary = "查詢策略庫:tactics_info列表",description = "查詢策略庫:tactics_info列表-list接口")@RequiresPermissions("business:tacticsInfo:list")@GetMapping("/list")public TableDataInfo list(TacticsInfo tacticsInfo){// ...
    }
    

在這里插入圖片描述

@ApiResponse 和 @ApiResponses
  • 作用:描述 API 方法的響應結果。
  • 常用屬性
    • responseCode:HTTP 狀態碼。
    • description:響應描述信息。
    • content:響應的內容類型(如 JSON、XML)。
  • 示例
    @Operation(summary = "創建用戶", description = "根據用戶信息創建新用戶")
    @ApiResponses({@ApiResponse(responseCode = "200", description = "成功創建用戶"),@ApiResponse(responseCode = "400", description = "請求參數錯誤"),@ApiResponse(responseCode = "500", description = "服務器內部錯誤")
    })
    @PostMapping
    public ResponseEntity<User> createUser(@RequestBody User user) {// ...
    }
    

3. 參數相關注解

@Parameter
  • 作用:描述方法參數的含義。
  • 常用屬性
    • name:參數名稱。
    • description:參數描述信息。
    • required:是否必填。
    • example:參數示例值。
    • in:參數位置(如 pathqueryheader 等)。
  • 示例
    @Operation(summary = "根據 ID 獲取用戶")
    @GetMapping("/{id}")
    public User getUserById(@Parameter(name = "id", description = "用戶 ID", required = true, example = "1") @PathVariable Long id) {// ...
    }
    
@Parameters
  • 作用:描述多個參數。
  • 示例
    @Operation(summary = "搜索用戶")
    @Parameters({@Parameter(name = "name", description = "用戶名", in = ParameterIn.QUERY),@Parameter(name = "age", description = "用戶年齡", in = ParameterIn.QUERY)
    })
    @GetMapping("/search")
    public List<User> searchUsers(@RequestParam String name, @RequestParam Integer age) {// ...
    }
    

4. 實體模型相關注解

@Schema
  • 作用:描述實體類或字段的信息。
  • 常用屬性
    • description:模型或字段的描述信息。
    • example:字段示例值。
    • required:字段是否必填。
    • type:字段的數據類型。
    • format:字段的格式(如 date-timeemail 等)。
  • 示例
    @Schema(description = "用戶的基本信息")
    public class User {@Schema(description = "用戶 ID", example = "1", required = true)private Long id;@Schema(description = "用戶名", example = "John Doe", required = true)private String name;@Schema(description = "用戶年齡", example = "25")private Integer age;// getters and setters
    }
    

5. 其他注解

@Hidden
  • 作用:隱藏某個類、方法或參數,不將其包含在生成的文檔中。
  • 示例
    @Hidden
    @GetMapping("/internal")
    public String internalEndpoint() {return "This endpoint is ignored by springdoc.";
    }
    

6. 配置相關注解(不常用)

@OpenAPIDefinition
  • 作用:全局配置 OpenAPI 文檔的元信息。這個不常用,還是常用配置文件類型的
  • 常用屬性
    • info:文檔的基本信息(標題、版本、描述等)。
    • tags:全局標簽定義。
    • servers:API 的服務器地址。
  • 示例
    @OpenAPIDefinition(info = @Info(title = "用戶管理系統", version = "1.0", description = "用戶相關的 API 文檔"),tags = {@Tag(name = "用戶管理", description = "與用戶相關的操作")},servers = {@Server(url = "http://localhost:8080", description = "本地開發環境")}
    )
    @SpringBootApplication
    public class Application {public static void main(String[] args) {SpringApplication.run(Application.class, args);}
    }
    

7. 總結

以下是 springdoc 常用注解的分類總結:

注解作用
@Tag為控制器或方法分組,便于組織和分類 API。
@Operation描述 API 方法的功能。
@ApiResponse描述單個響應結果。
@Parameter描述方法參數的含義。
@Schema描述實體類或字段的信息。
@Hidden隱藏某個類、方法或參數,不包含在生成的文檔中。
@OpenAPIDefinition全局配置 OpenAPI 文檔的元信息(標題、版本、描述等)。

四、在實際項目上如何使用

1、導包

在springboot中使用springdoc起步非常容易,只需要引入其starter即可

<dependency><groupId>org.springdoc</groupId><artifactId>springdoc-openapi-ui</artifactId><version>1.7.0</version> <!-- 版本可替換 -->
</dependency>

2、寫配置類

1)、配置實體類

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.License;/*** Swagger 配置屬性** @author wkl*/
@ConfigurationProperties(prefix = "springdoc")
public class SpringDocProperties
{/*** 網關*/private String gatewayUrl;/*** 文檔基本信息*/@NestedConfigurationPropertyprivate InfoProperties info = new InfoProperties();/*** <p>* 文檔的基礎屬性信息* </p>** @see io.swagger.v3.oas.models.info.Info** 為了 springboot 自動生產配置提示信息,所以這里復制一個類出來*/public static class InfoProperties{/*** 標題*/private String title = null;/*** 描述*/private String description = null;/*** 聯系人信息*/@NestedConfigurationPropertyprivate Contact contact = null;/*** 許可證*/@NestedConfigurationPropertyprivate License license = null;/*** 版本*/private String version = null;public String getTitle(){return title;}public void setTitle(String title){this.title = title;}public String getDescription(){return description;}public void setDescription(String description){this.description = description;}public Contact getContact(){return contact;}public void setContact(Contact contact){this.contact = contact;}public License getLicense(){return license;}public void setLicense(License license){this.license = license;}public String getVersion(){return version;}public void setVersion(String version){this.version = version;}}public String getGatewayUrl(){return gatewayUrl;}public void setGatewayUrl(String gatewayUrl){this.gatewayUrl = gatewayUrl;}public InfoProperties getInfo(){return info;}public void setInfo(InfoProperties info){this.info = info;}
}

2)、配置類

import java.util.ArrayList;
import java.util.List;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import com.wenge.common.swagger.config.properties.SpringDocProperties;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.servers.Server;/*** Swagger 文檔配置** @author ruoyi*/
@EnableConfigurationProperties(SpringDocProperties.class)
@ConditionalOnProperty(name = "springdoc.api-docs.enabled", havingValue = "true", matchIfMissing = true)
public class SpringDocAutoConfiguration
{@Bean@ConditionalOnMissingBean(OpenAPI.class)public OpenAPI openApi(SpringDocProperties properties){return new OpenAPI().components(new Components()// 設置認證的請求頭.addSecuritySchemes("apikey", securityScheme())).addSecurityItem(new SecurityRequirement().addList("apikey")).info(convertInfo(properties.getInfo())).servers(servers(properties.getGatewayUrl()));}public SecurityScheme securityScheme(){return new SecurityScheme().type(SecurityScheme.Type.APIKEY).name("Authorization").in(SecurityScheme.In.HEADER).scheme("Bearer");}private Info convertInfo(SpringDocProperties.InfoProperties infoProperties){Info info = new Info();info.setTitle(infoProperties.getTitle());info.setDescription(infoProperties.getDescription());info.setContact(infoProperties.getContact());info.setLicense(infoProperties.getLicense());info.setVersion(infoProperties.getVersion());return info;}public List<Server> servers(String gatewayUrl){List<Server> serverList = new ArrayList<>();serverList.add(new Server().url(gatewayUrl));return serverList;}
}

3、編寫配置參數

springdoc:api-docs:path: /v3/api-docsswagger-ui:path: /swagger-ui.htmlenabled: trueoperationsSorter: methodshow-actuator: true

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/898633.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/898633.shtml
英文地址,請注明出處:http://en.pswp.cn/news/898633.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

SpringBoot3+Vue3開發學生成績管理系統

系統介紹 此系統功能包含&#xff1a;首頁、課程管理、成績查詢、成績詳情、班級管理、專業管理、用戶管理等功能。用戶管理又細分為賬號管理、學生管理、教師管理、管理員管理。 基礎功能包含&#xff1a;登錄、退出、修改登錄人信息、修改登錄人密碼。 分為4種角色&#x…

康謀方案 | AVM合成數據仿真驗證方案

隨著自動駕駛技術的快速發展&#xff0c;仿真軟件在開發過程中扮演著越來越重要的角色。仿真傳感器與環境不僅能夠加速算法驗證&#xff0c;還能在安全可控的條件下進行復雜場景的重復測試。 本文將分享如何利用自動駕駛仿真軟件配置仿真傳感器與搭建仿真環境&#xff0c;并對…

深入解析 Java Stream API:從 List 到 Map 的優雅轉換!!!

&#x1f680; 深入解析 Java Stream API&#xff1a;從 List 到 Map 的優雅轉換 &#x1f527; 大家好&#xff01;&#x1f44b; 今天我們來聊聊 Java 8 中一個非常常見的操作&#xff1a;使用 Stream API 將 List 轉換為 Map。&#x1f389; 具體來說&#xff0c;我們將深入…

配置銀河麒麟V10高級服務器操作系統安裝vmware tools。在您的計算機上尚未找到用于此虛擬機的 VMwareTools。安裝將無法繼續。

配置銀河麒麟V10高級服務器操作系統安裝vmware tools 下載VMwareTools安裝包 通過網盤分享的文件&#xff1a;VMwareTools-10.3.25-20206839.tar.gz 鏈接: https://pan.baidu.com/s/1EgMcqbIEur4iyHu2l0v_gQ?pwdrc8m 提取碼: rc8m 通過工具上傳到指定目錄&#xff0c;然后切換…

突破 HTML 學習瓶頸:表格、列表與表單的學習進度(一)

HTML 學習之困&#xff0c;如何破局&#xff1f; 作為一名熱衷于網頁開發的博主&#xff0c;在 HTML 的學習道路上&#xff0c;我可謂是 “過關斬將”&#xff0c;但也遇到過不少 “硬茬”。起初&#xff0c;當我滿心歡喜地以為掌握了基本的 HTML 標簽&#xff0c;就能輕松搭建…

理一理Mysql日期

在 MySQL 數據庫中&#xff0c;關于日期和時間的類型主要有以下幾種&#xff1a; 1. **DATE**: 僅存儲日期部分&#xff0c;格式為 YYYY-MM-DD&#xff0c;例如 2023-10-31。 2. **TIME**: 僅存儲時間部分&#xff0c;格式為 HH:MM:SS&#xff0c;例如 14:30:00。 3. **DATE…

CEF 多進程模式時,注入函數,獲得交互信息

CEF 控制臺添加一函數,枚舉 注冊的供前端使用的CPP交互函數有哪些-CSDN博客 上篇文章,是在模擬環境,單進程中設置的,這篇文章,將其改到正常多進程環境中設置。 對應于工程中的 CEF_RENDER項目 一、多進程模式中,改寫 修改步驟 1、注入函數 client_app_render.cpp 在…

C++ 介紹STL底層一些數據結構

c 標準模板庫中&#xff0c;set和map的底層實現通常基于紅黑樹&#xff0c;然們都是平衡二叉搜索樹(Balanceed Binary Serach Tree&#xff09;的一種,這種結構保證了 插入&#xff0c;刪除&#xff0c;查找的時間復雜度為O(log n)比普通二叉搜索樹更高效。 set set<T>…

在 Kubernetes(k8s)部署過程中常見的問題

在 Kubernetes(k8s)部署過程中,常見的問題主要包括以下幾類,以下是具體示例及簡要說明: 1. 資源配額不足(Resource Quota) 現象:Pod 處于 Pending 狀態,事件日志顯示 Insufficient CPU/Memory。 原因: 節點(Node)資源不足,無法滿足 Pod 的 requests 或 limits。 命…

Android Window浮窗UI組件使用JetPack

目前接手的一個業務&#xff0c;應用不是用Activity/Fragment作為界面組件&#xff0c;而是用Window浮窗的形式顯示&#xff0c;并且浮窗有很多種類型&#xff0c;每一種類型對應一類業務。那么怎么使用Jatpack的相關特性來設計架構并提高開發效率呢&#xff1f;分下面幾個模塊…

基于WebRtc,GB28181,Rtsp/Rtmp,SIP,JT1078,H265/WEB融合視頻會議接入方案

智能融合視頻會議系統方案—多協議、多場景、全兼容的一站式視頻協作平臺 OvMeet,LiveMeet針對用戶?核心痛點實現功能與用戶價值 &#xff0c;Web平臺實現MCU多協議&#xff0c;H265/H264等不同編碼監控&#xff0c;直播&#xff0c;會議&#xff0c;調度資源統一融合在一套界…

深入淺出理解LLM PPO:基于verl框架的實現解析之一

1. 寫在前面 強化學習(Reinforcement Learning,RL)在大型語言模型(Large Language Model,LLM)的訓練中扮演著越來越重要的角色。特別是近端策略優化(Proximal Policy Optimization,PPO)算法,已成為對齊LLM與人類偏好的主流方法之一。本文將基于verl框架(很多復刻De…

卷積神經網絡 - 匯聚層

卷積神經網絡一般由卷積層、匯聚層和全連接層構成&#xff0c;本文我們來學習匯聚層。 匯聚層(Pooling Layer)也叫子采樣層(Subsampling Layer)&#xff0c;其作用是進 行特征選擇&#xff0c;降低特征數量&#xff0c;從而減少參數數量。 卷積層雖然可以顯著減少網絡中連接的…

vue使用element-ui自定義樣式思路分享【實操】

前言 在使用第三方組件時&#xff0c;有時候組件提供的默認樣式不滿足我們的實際需求&#xff0c;需要對默認樣式進行調整&#xff0c;這就需要用到樣式穿透。本篇文章以vue3使用element-ui的Tabs組件&#xff0c;對Tabs組件的添加按鈕樣式進行客制化為例。 確定需要修改的組…

【工具分享】vscode+deepseek的接入與使用

目錄 第一章 前言 第二章 獲取Deepseek APIKEY 2.1 登錄與充值 2.2 創建API key 第三章 vscode接入deepseek并使用 3.1 vscode接入deepseek 3.2 vscode使用deepseek 第一章 前言 deepseek剛出來時有一段時間余額無法充值&#xff0c;導致小編沒法給大家發完整的流程&…

【藍橋杯速成】| 9.回溯升級

題目一&#xff1a;組合綜合 問題描述 39. 組合總和 - 力扣&#xff08;LeetCode&#xff09; 給你一個 無重復元素 的整數數組 candidates 和一個目標整數 target &#xff0c;找出 candidates 中可以使數字和為目標數 target 的 所有 不同組合 &#xff0c;并以列表形式返…

【C++進階】深入探索類型轉換

目錄 一、C語言中的類型轉換 1.1 隱式類型轉換 1.2. 顯式類型轉換 1.3.C語言類型轉換的局限性 二、C 類型轉換四劍客 2.1 static_cast&#xff1a;靜態類型轉換&#xff08;編譯期檢查&#xff09; 2.2 dynamic_cast&#xff1a;動態類型轉換&#xff08;運行時檢查&…

代碼隨想錄_動態規劃

代碼隨想錄 動態規劃 509.斐波那契數 509. 斐波那契數 斐波那契數 &#xff08;通常用 F(n) 表示&#xff09;形成的序列稱為 斐波那契數列 。該數列由 0 和 1 開始&#xff0c;后面的每一項數字都是前面兩項數字的和。也就是&#xff1a; F(0) 0&#xff0c;F(1) 1 F(n…

計算機基礎:編碼03,根據十進制數,求其原碼

專欄導航 本節文章分別屬于《Win32 學習筆記》和《MFC 學習筆記》兩個專欄&#xff0c;故劃分為兩個專欄導航。讀者可以自行選擇前往哪個專欄。 &#xff08;一&#xff09;WIn32 專欄導航 上一篇&#xff1a;計算機基礎&#xff1a;編碼02&#xff0c;有符號數編碼&#xf…

設計模式(創建型)-單例模式

摘要 在軟件開發的世界里&#xff0c;設計模式是開發者們智慧的結晶&#xff0c;它們為解決常見問題提供了經過驗證的通用方案。單例模式作為一種基礎且常用的設計模式&#xff0c;在許多場景中發揮著關鍵作用。本文將深入探討單例模式的定義、實現方式、應用場景以及可…