在spring_clude的配置文件application.yml 文件中加入以下配置:
server:
port: 8200 #服务端口
spring:
application:
name: service-zuul #指定服务名
###服务注册到eureka注册中心的地址
eureka:
client:
service-url:
defaultZone: http://kate:123456@127.0.0.1:8100/eureka/
###因为该应用为服务提供者,是eureka的一个客户端,需要注册到注册中心
register-with-eureka: true
###是否需要从eureka上检索服务
fetch-registry: true
# instance:
# prefer-ip-address: true #将自己的ip地址注册到Eureka服务中
# ip-address: 127.0.0.1
# instance-id: ${spring.application.name}###${server.port} #指定实例id
#浏览器:http://localhost:8200/order/order3/201810300001
#zuul路由为:http://127.0.0.1:8081/order3/201810300001
方式一:path+serviceId
zuul:
routes: #定义服务转发规则(lu)
abc: #abc这个名字任意取的,表示路由的规则名称
# path: /order/** #配置请求URL的请求规则
# url: http://127.0.0.1:8081 #真正的微服务地址,path匹配的请求都转发到这里 http://127.0.0.1:8081/order3/201810300001
# serviceid: service-order
方式二:指定服务id
# service-order: /order/**
方式三:同时配置path和url
#path: /order/**
# url: http://127.0.0.1:8091 #真正的微服务地址,path匹配的请求都转发到这里
方式四:路由前缀方式1
# prefix: /order3
# strip-prefix: false
# routes:
# app-order: /order/**
#地址:http://127.0.0.2:8200/order3/app-order/201810300001
方式五:路由前缀方式2
routes:
app-order:
path: /order3/**
strip-prefix: false
# 地址:http://localhost:8200/order3/201810300001
原文:https://www.cnblogs.com/1372841965ZQ/p/14312236.html