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

选择导入

然后就可以使用了~


相关推荐
青云交几秒前
Java 大视界 -- 基于 Java 的大数据分布式存储在数字媒体内容存储与版权保护中的应用
java·性能优化·区块链·分布式存储·版权保护·数字媒体·ai 识别
武子康2 分钟前
大数据-166 Apache Kylin 1.6 Streaming Cubing 实战:Kafka 到分钟级 OLAP
大数据·后端·apache kylin
回家路上绕了弯7 分钟前
彻底解决超卖问题:从单体到分布式的全场景技术方案
分布式·后端
踢球的打工仔18 分钟前
PHP面向对象(5)
android·java·php
Rover.x20 分钟前
错误:找不到或无法加载主类 @C:\Users\AppData\Local\Temp\idea_arg_file223456232
java·ide·intellij-idea
4***172722 分钟前
使用 java -jar 命令启动 Spring Boot 应用时,指定特定的配置文件的几种实现方式
java·spring boot·jar
8***293125 分钟前
能懂!基于Springboot的用户增删查改(三层设计模式)
spring boot·后端·设计模式
落子摘星26 分钟前
suricata学习杂记(一)
学习·modbus·suricata·pdu
CoderYanger38 分钟前
优选算法-字符串:63.二进制求和
java·开发语言·算法·leetcode·职场和发展·1024程序员节
3***312139 分钟前
java进阶1——JVM
java·开发语言·jvm