一 介绍
配置zuul.routes.指定微服务的serviceid=指定路径。例如:
zuul:
  routes:
    users: /myusers/**

二 实战
1 修改配置如下:
server:
  port: 8040
spring:
  application:
    name: microservice-gateway-zuul
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/
  instance:
    prefer-ip-address: true
zuul:
  routes:
    microservice-provider-user: /user/**
2 地址栏输入 http://localhost:8040/user/1
3 地址栏输入 http://localhost:8001/1
可以获得同样的结果
4 说明
当输入 http://localhost:8040/user/1,由配置microservice-provider-user: /user/**可知,会路由到microservice-provider-user微服务,microservice-provider-user微服务对应的URL为 http://localhost:8001
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐