10.使用微服务网关Zuul统一管理swaggerApi

使用微服务网关Zuul统一管理swaggerApi

1.创建项目shop-basics-springcloud-zuul
在这里插入图片描述
2.引入Maven依赖

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

3.在SpringBoot启动类添加统一管理API代码

@SpringBootApplication
@EnableEurekaClient
@EnableZuulProxy
@EnableSwagger2Doc
public class AppGateWay {

	public static void main(String[] args) {
		SpringApplication.run(AppGateWay.class, args);
	}

	// 添加文档来源
	@Component
	@Primary
	class DocumentationConfig implements SwaggerResourcesProvider {
		@Override
		public List<SwaggerResource> get() {
			List resources = new ArrayList<>();

			resources.add(swaggerResource("app-bajin-member", "/app-bajin-member/v2/api-docs", "2.0"));
			resources.add(swaggerResource("app-bajin-weixin", "/app-bajin-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;
		}

	}

}

4.增加配置文件

###服务启动端口号
server:
  port: 80
###服务名称(服务注册到eureka名称)  
spring:
    application:
        name: app-bajin-zuul
###服务注册到eureka地址
eureka:
  client:
    service-url:
           defaultZone: http://localhost:8100/eureka


### 配置网关反向代理    
zuul:
  routes:
    api-a:
     ### 以 /api-weixin/访问转发到会员服务
      path: /api-weixin/**
      serviceId: app-bajin-weixin
    api-b:
        ### 以 /api-member/访问转发到订单服务
      path: /api-member/**
      serviceId: app-bajin-member

5.在浏览器输入如下地址访问

http://127.0.0.1/swagger-ui.html

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值