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中操作

选择导入

然后就可以使用了~


相关推荐
我命由我123454 小时前
财务学习 - 配比原则
学习·职场和发展·产品运营·求职招聘·职场发展·产品经理·学习方法
古法安卓4 小时前
Android-显示流程
android·java·android studio
李昊哲小课4 小时前
SpringBoot4 云端咖啡站 阶段五:交付与进阶
人工智能·spring boot·大模型·log4j·智能体
码事漫谈4 小时前
项目探测:把老项目的知识变成 AI 的外部记忆
后端
BFT白芙堂4 小时前
Franka & DROID :面向真实场景的机器人操作数据集
人工智能·学习·机器学习·机器人·具身智能·franka·robotiq
PragmaticWorks4 小时前
从"遍地 try-catch"到分层治理:用 pragmatic-ddd 的异常体系治好代码洁癖
后端·领域驱动设计
苍何5 小时前
我的开源项目登顶 GitHub 趋势榜 No1 了!
后端
l1t5 小时前
DeepSeek总结的DuckDB 如何更快地运行递归 CTE
java·开发语言·数据库·mysql·duckdb
M78佐菲5 小时前
Linux多线程:创建、回收与互斥同步
linux·笔记·学习·算法
小手cool5 小时前
使用递归对数组进行反转操作
java·数据结构·算法