我使用Spring Boot + Cloud | Zuul代理(org.springframework.cloud:spring-cloud-starter-zuul:1.0.0.RELEASE)。我有以下配置。
info:
component: Zuul Server
endpoints:
restart:
enabled: true
shutdown:
enabled: true
health:
sensitive: false
zuul:
ignoredServices: "*"
proxy:
mapping: /api/v1
addProxyHeaders: true
routes:
service:
path: /service/**
serviceId: service
stripPrefix: false
server:
port: 8765
logging:
level:
ROOT: INFO
org.springframework.web: INFO
eureka:
instance:
preferIpAddress: true
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
我希望访问网址服务为http://localhost:8765/api/v1/service,如上面的配置所述(参考:https://github.com/joshlong/microservices-lab/blob/master/api-gateway/gateway/src/main/resources/application.yml)。
但这不起作用,网址http://localhost:8765/service有效。
有没有办法实现这一点,因为我不希望个别服务拥有/ api / v1上下文。
答案 0 :(得分:2)
不确定您获得zuul.proxy.*
选项的位置。它们无效。 zuul.addProxyHeaders
有效。
你想要的是zuul.prefix=/api/v1
。默认设置是在转发时去除该前缀。因此/api/v1/service
转发到/service
。