单体、zuul、gateway集成swagger(亲测)

分三块介绍:
一、单体应用集成swagger
二、zuul网关集成swagger
三、gateway网关集成swagger集成spring security oauth2

标题单体应用集成swagger

一、pom添加坐标

<dependency>
    <groupId>com.spring4all</groupId>
    <artifactId>swagger-spring-boot-starter</artifactId>
    <version>1.9.1.RELEASE</version>
</dependency>

二、启动类加开启注解

@EnableSwagger2Doc

三、配置文件添加配置

server:
  port: 9001
swagger:
  base-package: com.funtl.myshop.plus.business
  title: SpringCloud2.x构建XXXX项目-会员服务接口
  description: 该项目。。。。。。。
  version: 1.1
  terms-of-service-url: www.baidu.com
  contact:
    name: 作者名字
    email: [email protected]
  enabled: true
  authorization:
    key-name: Authorization

四、访问链接

localhost:9001/swagger-ui.html

zuul网关集成swagger

在单体应用集成的基础上,配置zuul网关集成swagger。

一、在网关pom添加坐标

<dependency>
    <groupId>com.spring4all</groupId>
    <artifactId>swagger-spring-boot-starter</artifactId>
    <version>1.9.1.RELEASE</version>
</dependency>

二、在网关启动类加开启注解

@EnableSwagger2Doc

三、在网关配置文件中配置路由

##服务启动端口号
server:
  port: 8080
## 配置网关反向代理    
zuul:
  routes:
    api-a:
     ### 以 /api-weixin/访问转发到会员服务
      path: /api-weixin/**
      serviceId: app-mayikt-weixin
    api-b:
        ### 以 /api-member/访问转发到订单服务
      path: /api-member/**
      serviceId: app-mayikt-member

四、在启动类上添加配置

 // 添加文档来源
	@Component
	@Primary
	class DocumentationConfig implements SwaggerResourcesProvider {
   
		@Override
		public List<SwaggerResource> get() {
   
			List resources = new ArrayList<>();
			// app-itmayiedu-order
			// 网关使用服务别名获取远程服务的SwaggerApi
			resources.add(swaggerResource("app-mayikt-member", "/app-mayikt-member/v2/api-docs", "2.0"));
			resources.add(swaggerResource("app-mayikt-weixin", "/app-mayikt-weixin/v2/api-docs", "2.0"));
			return resources;
		}

		private SwaggerResource swaggerResource(String name, String location, String version) {
   
			SwaggerResource swaggerResource = new SwaggerResource();
			swaggerResource.setName(name);
			swaggerResource.setLocation(location);
			swaggerResource.setSwaggerVersion(version);
			return swaggerResource;
		}

	}

五、访问链接

localhost:8080
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值