springcloud——gateway配置动态路由

主配置文件

#设置端口号
server:
  port: 9527

#指定微服务的名称
spring:
  application:
    name: cloud-gateway

  cloud:
    gateway:
      routes:
        #设置路由的id
        - id: payment_routh
          #设置路由的路径
          #uri: http://localhost:8081
          #lb是LoadBalancer(负载均衡)的意思
          uri: lb://payment-provider  #lb://serviceName是springcloud gateway在微服务中自动为我们创建的负载均衡uri。
          #设置路由的拦截点
          predicates:
            - Path=/payment/first/**

        #设置路由的id
        - id: payment_routh2
          #设置路由的路径
          #uri: http://localhost:8081
          #lb是LoadBalancer(负载均衡)的意思
          uri: lb://payment-provider  #lb://serviceName是springcloud gateway在微服务中自动为我们创建的负载均衡uri。
          #设置路由的拦截点
          predicates:
            - Path=/payment/second/**
      discovery:
        locator:
          enabled: true   #开启从注册中心动态创建路由的功能,利用微服务名进行路由


eureka:
  client:
    fetch-registry: true
    register-with-eureka: true
    service-url:
      defaultZone: http://eureka7001.com:7001/eureka/

  #设置主机名
  instance:
    instance-id: cloud-gateway-service

猜你喜欢

转载自blog.csdn.net/weixin_43925059/article/details/107766681