【问题标题】:Spring Boot + Cloud | Zuul Proxy | Append a URL/rewriteSpring Boot + 云 | Zuul 代理 |附加 URL/重写
【发布时间】:2015-11-28 19:53:07
【问题描述】:

我正在使用 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/

我希望访问 URL 以 http://localhost:8765/api/v1/service 为服务,如上述配置中所做的那样(参考:https://github.com/joshlong/microservices-lab/blob/master/api-gateway/gateway/src/main/resources/application.yml)。

但这不起作用,URL http://localhost:8765/service 有效。

有没有办法实现这一点,因为我不希望单个服务具有 /api/v1 上下文。

【问题讨论】:

    标签: spring-boot spring-cloud netflix-zuul


    【解决方案1】:

    不确定您从哪里获得zuul.proxy.* 选项。它们无效。 zuul.addProxyHeaders 有效。

    你想要的是zuul.prefix=/api/v1。默认是在转发时去除该前缀。所以/api/v1/service 转发到/service

    【讨论】:

    • @spencergibb 那么 /api/v2/service 会发生什么?维护到同一 API 的不同版本的路由映射的最佳方法是什么?
    猜你喜欢
    • 2015-05-23
    • 2016-04-13
    • 2017-01-20
    • 2016-03-21
    • 1970-01-01
    • 2016-10-28
    • 2017-11-13
    • 2016-05-28
    • 1970-01-01
    相关资源
    最近更新 更多