实现Spring Cloud Alibaba ,Gateway集成Knife4j

实现Spring Cloud Alibaba ,Gateway集成Knife4j

本篇博客主要讲解通过knife4j项目如何集成Spring Cloud Gateway网关,通过网关聚合所有的Swagger微服务文档

源码地址:https://gitee.com/xiaoym/swagger-bootstrap-ui-demo/tree/master/knife4j-spring-cloud-gateway

官方文档:https://doc.xiaominfo.com/knife4j/action/springcloud-gateway.html

源码整体项目结构如下:

|-knife4j-spring-cloud-gateway
|-----service-doc	//文档聚合中心,是所有微服务文档的出口
|-----service-order //订单服务,包含所有与订单业务模块相关的接口
|-----service-server //eureka 注册中心
|-----service-user //用户服务,包含所有的用户接口

Alibaba就不要用到eureka

Nacos的配置和Eureka几乎一模一样,唯一不同的区别是在yml进行配置的时候,使用的是knife4j.nacos开头,其他基本都是一样,所以就只要用到这两个模块即可:

|-----service-doc	//文档聚合中心,是所有微服务文档的出口
|-----service-order //订单服务,包含所有与订单业务模块相关的接口

以下的application.yaml都是从作者自己项目里复制过来的,可以根据自己的实际情况改一下

service-doc

源码地址:https://gitee.com/xiaoym/swagger-bootstrap-ui-demo/blob/master/knife4j-spring-cloud-gateway/service-order/src/main/java/com/xiaominfo/swagger/service/order/config/SwaggerConfiguration.java

对应Spring Cloud内有controller的模块块:
请添加图片描述

package com.xiaominfo.swagger.service.order.config;

import com.github.xiaoymin.knife4j.core.util.CollectionUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.annotation.Order;
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.*;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.contexts.SecurityContext;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

import java.util.List;


@Configuration
@EnableSwagger2WebMvc
@Import(BeanValidatorPluginsConfiguration.class)
public class SwaggerConfiguration {

    @Bean(value = "orderApi")
    @Order(value = 1)
  
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值