SpringBoot使用Gateway聚合Springdoc,Knife4j

SpringBoot使用Gateway聚合Springdoc,Knife4j

前言

同时支持springboot:3.0,springboot:2.0,使用gateway聚合springdoc,ui使用knife4j,解决由于nginx配置代理前缀导致的文档无法访问,不强依赖注册中心(nacos,zk,Eureka)

有帮助的话记得点个赞哟!!!

基础环境

将所有依赖集成好作为一个本地包供其他项目使用

  • jdk17
  • maven3.6+
  • springboot3.0+|springboot2.0+
  • springcloud:2022.0.1
  • springcloud-alibaba:1.8.1-2022.0.0-RC2
  • springdoc:2.0.2|springdoc:1.6.0+
  • knife4j:4.0.0

当使用springboot:3.0,请使用 springdoc:2.0.0+
当使用springboot:2.0,请使用 springdoc:1.6.0+(部分springdoc的包名替换即可)

工具包(framework-document)

依赖

<dependencies>
    <dependency>
        <groupId>org.springdocgroupId>
        <artifactId>springdoc-openapi-starter-webmvc-apiartifactId>
        <scope>providedscope>
    dependency>
    <dependency>
        <groupId>org.springdocgroupId>
        <artifactId>springdoc-openapi-starter-webflux-apiartifactId>
        <scope>providedscope>
    dependency>
    <dependency>
        <groupId>org.springframework.cloudgroupId>
        <artifactId>spring-cloud-starter-gatewayartifactId>
        <scope>providedscope>
    dependency>
dependencies>

代码

文档信息properties
import com.github.mpcloud.framework.core.consts.Constant;
import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * The type Swagger properties.
 *
 * @author : Milo
 */
@ConfigurationProperties("springdoc.info")
public class DocumentInfoProperties {
   
    private static final String DEFAULT_OPEN_API_ROUTE_NAME = "open-api-route";
    private static final String DEFAULT_GATEWAY_API_ROUTE_NAME = "open-api-gateway-route";
    /**
     * 文档标题
     */
    private String title;
    /**
     * 文档描述
     */
    private String description;
    /**
     * 项目version
     */
    private String projectVersion;
    /**
     * 许可证
     */
    private String license;
    /**
     * 许可证URL
     */
    private String licenseUrl;
    /**
     * 项目负责人信息
     */
    private final Contact contact = new Contact();
    /**
     * gateway
     */
    private final Gateway gateway = new Gateway();

    public String getTitle() {
   
        return this.title;
    }

    public void setTitle(final String title) {
   
        this.title = title;
    }

    public String getDescription() {
   
        return this.description;
    }

    public void setDescription(final String description) {
   
        this.description = description;
    }

    public String getProjectVersion() {
   
        return this.projectVersion;
    }

    public void setProjectVersion(final String projectVersion) {
   
        this.projectVersion = projectVersion;
    }

    public String getLicense() {
   
        return this.license;
    }

    public void setLicense(final String license) {
   
        this.license = license;
    }

    public String getLicenseUrl() {
   
        return this.licenseUrl;
    }

    public void setLicenseUrl(final String licenseUrl) {
   
        this.licenseUrl = licenseUrl;
    }

    public Contact getContact() {
   
        return this.contact

你可能感兴趣的:(SpringCloud,gateway,spring,java,nginx)