当前位置:   article > 正文

springcloud之gateway路由网关配置_gateway自动路由配置访问路径去除服务名前缀

gateway自动路由配置访问路径去除服务名前缀

1.添加依赖

  1. <dependency>
  2. <groupId>org.springframework.cloud</groupId>
  3. <artifactId>spring-cloud-starter-gateway</artifactId>
  4. </dependency>

2.springboot启动类加上@EnableEurekaClient

3.application.yml的配置

  1. #端口
  2. server:
  3. port: 16000
  4. #服务名
  5. spring:
  6. application:
  7. name: gateway
  8. cloud:
  9. gateway:
  10. routes: #路由配置:参数为一个List
  11. - id: consumer-9090 #唯一标识
  12. uri: lb://RIBBON-CONSUMER #转发的地址,写服务名称
  13. predicates:
  14. - Path=/ribbon/** #判断匹配条件,即地址带有/ribbon/**的请求,会转发至lb:RIBBON-CONSUMER
  15. filters:
  16. - StripPrefix=1 #去掉Path前缀,参数为1代表去掉/ribbon
  17. - id: consumer-9091
  18. uri: lb://FEIGN-CONSUMER
  19. predicates:
  20. - Path=/feign/**
  21. filters:
  22. - StripPrefix=1
  23. eureka:
  24. client:
  25. service-url:
  26. defaultZone: http://www.aaa.com:10000/eureka,http://www.bbb.com:10001/eureka,http://www.ccc.com:10002/eureka

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/301372
推荐阅读
相关标签
  

闽ICP备14008679号