Spring Boot 3.x 配置 Spring Doc以及导入postman带图详解

一、pom.xml配置

XML 复制代码
<!-- API⽂档⽣成,基于swagger3 -->
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
            <version>2.0.2</version>
        </dependency>

        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
            <version>2.0.2</version>
        </dependency>

二、配置 yml 文件

XML 复制代码
server:
 port: 58080 # 指定端⼝号

springdoc:
  api-docs:
    enabled: true # 开启OpenApi接口
    path: /v3/api-docs  # 自定义路径,默认为 "/v3/api-docs"
  swagger-ui:
    enabled: true # 开启swagger界面,依赖OpenApi,需要OpenApi同时开启
    path: /swagger-ui/index.html # 自定义路径,默认为"/swagger-ui/index.html"

后续访问的url端口号要通过配置的端口号来访问,如果没配置就是 8080。

**三、**SpringDocConfig文件配置

java 复制代码
// 你自己的包名
package org.example.xxxx;

import io.swagger.v3.oas.models.ExternalDocumentation;
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;


@Configuration
public class SpringDocConfig {
    @Bean
    public OpenAPI springShopOpenAPI() {
        return new OpenAPI()
                .info(new Info().title("Spring Boot 中使用 Swagger UI 构建 RESTful API")
                        .contact(new Contact())
                        .description("百草中医药信息管理平台提供的 RESTful API")
                        .version("v1.0.0")
                        .license(new License().name("Apache 2.0").url("http://springdoc.org")))
                .externalDocs(new ExternalDocumentation()
                        .description("外部文档")
                        .url("https://springshop.wiki.github.org/docs"));
    }
}

四、访问

访问网址:localhost:58080/swagger-ui/swagger-ui/index.html#/

复制到浏览器访问,端口号需改成自己的

(我的是58080,复制记得改成自己的)

五、如何导入postman

然后在postman中操作

选择导入

然后就可以使用了~


相关推荐
想不到一个好的ID6 小时前
Redis Cluster
后端
EatFan6 小时前
Spring Boot 4.0 升级清单:JDK 基线、Jakarta 命名空间、Observation API 与第三方组件兼容一次讲清
java·spring boot·后端
大大大大晴天6 小时前
从System.out到可观测性:Java 日志框架的演进与选型
后端
辰海Coding6 小时前
平台如何接入一台物联网设备?又该如何设计它的通信协议?
java·物联网
代码民工正电荷7 小时前
JAVA重要知识点和集合
java·开发语言
kitsch0x977 小时前
技术学习_Cowrie 蜜罐的响应机制
学习
李少兄8 小时前
IDEA Apifox Helper 插件踩坑:2.0.15-243 版本“导出指定接口”参数描述丢失问题解析与修复方案
java·ide·intellij-idea
JavaGuide8 小时前
Gemini 杀疯了,反重力给我用爽了!分享 8 个 Antigravity 使用技巧
人工智能·后端
kyrie_sakura8 小时前
大模型学习32 --大模型微调3 -- 分布式训练算法
分布式·学习·算法
xwz小王子8 小时前
Nature Custom Media 从手术台到厨房:下一代医疗机器人,正在学习“什么时候该放手”
人工智能·学习·机器人