SpringCloudGateway与swagger集成解决方案

spring cloud gateway 底层采用的是webflux,swagger2暂时不支持webflux,网上的解决方案虽然有一些,比如这篇文章 还有《重新定义spring cloud 实战》这本书也有解决方案,书源码链接,
我们项目里面采用的是集成了最新的swagger3 snapshot版本,需要引入的pom文件有:

坚守“ 做人真诚 · 做事靠谱 · 口碑至上 · 高效敬业 ”的价值观,专业网站建设服务10余年为成都PE包装袋小微创业公司专业提供成都定制网站营销网站建设商城网站建设手机网站建设小程序网站建设网站改版,从内容策划、视觉设计、底层架构、网页布局、功能开发迭代于一体的高端网站建设服务。

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-integration</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.integration</groupId>
            <artifactId>spring-integration-webflux</artifactId>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>3.0.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-spring-webflux</artifactId>
            <version>3.0.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-spring-integration-webflux</artifactId>
            <version>3.0.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>3.0.0-SNAPSHOT</version>
            <exclusions>
                <exclusion>
                    <groupId>ch.qos.logback</groupId>
                    <artifactId>logback-classic</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>ch.qos.logback</groupId>
                    <artifactId>logback-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

                还要引入资源库
                <repositories>
        <repository>
            <id>jcenter-snapshots</id>
            <name>jcenter</name>
            <url>http://oss.jfrog.org/simple/oss-snapshot-local/io/springfox/</url>
            <releases>
               <enabled>false</enabled>
            </releases>
            <snapshots>
               <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>

因为公司的构建系统只代理这几个仓库:
http://repo1.maven.org/maven2/
http://jcenter.bintray.com/
http://repo.grails.org/grails/core/

所以虽然本地可以调试,但是服务器上构建失败,最后结局方案是,把swagger3的jar包引入本地lib文件,然后在pom中引入,解决问题。这是一个细心的活~
pom文件

<dependency>
            <groupId>classgraph</groupId>
            <artifactId>classgraph</artifactId>
            <version>4.1.7</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/classgraph-4.1.7.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>classmate</groupId>
            <artifactId>classmate</artifactId>
            <version>1.4.0</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/classmate-1.4.0.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>mapstruct</groupId>
            <artifactId>mapstruct</artifactId>
            <version>1.2.0.Final</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/mapstruct-1.2.0.Final.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>rawhttp</groupId>
            <artifactId>rawhttp</artifactId>
            <version>2.0</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/rawhttp-core-2.0.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>springfox</groupId>
            <artifactId>springfox</artifactId>
            <version>3.0.0-SNAPSHOT</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/springfox-core-3.0.0-SNAPSHOT.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>springfox</groupId>
            <artifactId>springfox-schema</artifactId>
            <version>3.0.0-SNAPSHOT</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/springfox-schema-3.0.0-SNAPSHOT.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>springfox</groupId>
            <artifactId>springfox-spi</artifactId>
            <version>3.0.0-SNAPSHOT</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/springfox-spi-3.0.0-SNAPSHOT.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>springfox</groupId>
            <artifactId>springfox-spring-integration</artifactId>
            <version>3.0.0-SNAPSHOT</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/springfox-spring-integration-3.0.0-SNAPSHOT.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>springfox</groupId>
            <artifactId>springfox-spring-integration-webflux</artifactId>
            <version>3.0.0-SNAPSHOT</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/springfox-spring-integration-webflux-3.0.0-SNAPSHOT.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>springfox</groupId>
            <artifactId>springfox-spring-web</artifactId>
            <version>3.0.0-SNAPSHOT</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/springfox-spring-web-3.0.0-SNAPSHOT.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>springfox</groupId>
            <artifactId>springfox-spring-webflux</artifactId>
            <version>3.0.0-SNAPSHOT</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/springfox-spring-webflux-3.0.0-SNAPSHOT.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>3.0.0-SNAPSHOT</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/springfox-swagger2-3.0.0-SNAPSHOT.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>springfox</groupId>
            <artifactId>springfox-swagger-common</artifactId>
            <version>3.0.0-SNAPSHOT</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/springfox-swagger-common-3.0.0-SNAPSHOT.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>3.0.0-SNAPSHOT</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/springfox-swagger-ui-3.0.0-SNAPSHOT.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>spring</groupId>
            <artifactId>spring-plugin-core</artifactId>
            <version>1.2.0.RELEASE</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/spring-plugin-core-1.2.0.RELEASE.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>spring</groupId>
            <artifactId>spring-plugin-metadata</artifactId>
            <version>1.2.0.RELEASE</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/spring-plugin-metadata-1.2.0.RELEASE.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>swagger</groupId>
            <artifactId>swagger-annotations</artifactId>
            <version>1.5.20</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/swagger-annotations-1.5.20.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>swagger</groupId>
            <artifactId>swagger-models</artifactId>
            <version>1.5.20</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/swagger-models-1.5.20.jar</systemPath>
        </dependency>

lib库截图:
SpringCloud Gateway与swagger集成解决方案

springfox提供的快照版本:https://springfox.github.io/springfox/docs/current/#maven
希望swagger官方尽早提供swagger3的release版本。

新闻标题:SpringCloudGateway与swagger集成解决方案
标题路径:https://www.cdcxhl.com/article40/gpigeo.html

成都网站建设公司_创新互联,为您提供网站策划微信公众号网站设计公司虚拟主机小程序开发响应式网站

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都定制网站网页设计