当前位置: 首页 > news >正文

SpringDoc集成到Springboot

1.Maven引入jar包

           <dependency><groupId>org.springdoc</groupId><artifactId>springdoc-openapi-ui</artifactId><version>1.6.14</version> </dependency>

2.新建OpenApiConfig文件,代码如下

package com.elane.project.ztt.config;import io.swagger.v3.oas.annotations.enums.SecuritySchemeIn;
import io.swagger.v3.oas.annotations.enums.SecuritySchemeType;
import io.swagger.v3.oas.annotations.security.SecurityScheme;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;//swagger显示Authorization
//@SecurityScheme(
//        name = "bearerAuth",  // 安全方案的唯一名称
//        type = SecuritySchemeType.HTTP,
//        scheme = "bearer",
//        bearerFormat = "JWT"  // 可选,表明 Token 格式为 JWT
//)
//将未登录header中的Authorization替换为sid
@SecurityScheme(name = "sid",type = SecuritySchemeType.APIKEY,in = SecuritySchemeIn.HEADER,paramName = "sid"
)
@Configuration
public class OpenApiConfig {@Beanpublic OpenAPI customOpenAPI() {return new OpenAPI().info(new Info().title("API文档").version("1.0").description("API文档描述")).addSecurityItem(new SecurityRequirement().addList("sid"));}
}

3.application.yml文件增加如下配置

springdoc:api-docs:path: /v3/api-docs # 更改 API 文档路径swagger-ui:path: /swagger-ui.html # 更改 Swagger UI 路径disable-swagger-default-url: true # 禁用默认 URL 加载operations-sort-parameter: alpha # 按字母顺序排序 API

4.注意 

如果在项目中使用过SpringFox,需要将SpringFox的依赖全部移除 

http://www.xdnf.cn/news/964549.html

相关文章:

  • 第1章信息化知识归纳总结补充内容
  • day52 ResNet18 CBAM
  • Canfestival的移植思想
  • EndNote 21完整安装指南:从零开始的详细步骤(附EndNote下载安装包)
  • HTML 文本省略号
  • HTML 标签 综合案例
  • 在鸿蒙HarmonyOS 5中HarmonyOS应用开发实现QQ音乐风格的播放功能
  • CppCon 2015 学习:Improving the future<T> with monads
  • MinHook 对.NET底层的 SendMessage 拦截真实案例反思
  • PHP和Node.js哪个更爽?
  • 【论文阅读】多任务学习起源类论文《Multi-Task Feature Learning》
  • MyBatis注解开发的劣势与不足
  • LeetCode--27.移除元素
  • Leetcode 3578. Count Partitions With Max-Min Difference at Most K
  • HTML 列表、表格、表单
  • Docker-containerd-CRI-CRI-O-OCI-runc
  • 【kafka】Golang实现分布式Masscan任务调度系统
  • Python 自动化临时邮箱工具,轻松接收验证码,支持调用和交互模式(支持谷歌gmail/googlemail)
  • 【C++】26. 哈希扩展1—— 位图
  • 【PhysUnits】17.5 实现常量除法(div.rs)
  • Linux上并行打包压缩工具
  • Cryosparc: Local Motion Correction注意输出颗粒尺寸
  • 基于大模型的输尿管下段结石诊疗全流程预测与方案研究
  • 多场景 OkHttpClient 管理器 - Android 网络通信解决方案
  • 【AI study】ESMFold安装
  • Ribbon负载均衡实战指南:7种策略选择与生产避坑
  • 深度学习核心概念:优化器、模型可解释性与欠拟合
  • 【无标题新手学习期权从买入看涨期权开始】
  • OpenCV 图像像素值统计
  • Python入门手册:常用的Python标准库