serviceId 的 Zuul 路由不起作用

Ser*_*gii 1 routing spring service-discovery spring-cloud netflix-zuul

我在不同的帖子上遇到过类似的问题,但它们对我来说毫无用处(没有答案或没有有用的答案)。我将在这里描述所有细节,希望得到帮助。

我用的是java8,spring boot 2.0.3,spring cloud元素基于Finchley.RELEASE版本。

在我的测试微服务应用程序中,我有下一个服务:config-serverdiscovery-service (Eureka)、edge-service (zuul)、card-service。所有服务在开始时从configuration-server加载它们自己的配置。服务启动没有问题。

card-service - 在开始时获取随机端口。这是将 zuul 路由配置为 calendar-service by 的原因serviceId

zuul:
  debug:
    request: true
  routes:
    card-service:
        path: /card-service/**
        serviceId: card-service
        stripPrefix: true
Run Code Online (Sandbox Code Playgroud)

使用发现服务客户端,我检测到下一个注册的服务["edge-server", "card-service"]。所以zuul路由使用相同的serviceId( card-service)。服务名称是正确的,因为它在card-service app 中是相同的bootstrap.yml

spring:
  application:
    name: card-service
Run Code Online (Sandbox Code Playgroud)

我使用直接访问card-service

http://localhost:59496/card-service/api/cards

http://localhost:59496/api/cards

(我为它配置了相同的结果)。- 工作正常。

我的 Zuul(边缘服务器8765端口上启动)所以我希望通过

http://localhost:8765/card-service/api/cards

给出相同的结果。但结果是空的。检查边缘服务器日志:

No handler mapping found for [/card-service/api/cards]
Last-Modified value for [/card-service/api/cards] is: -1
Run Code Online (Sandbox Code Playgroud)

通过执行器映射检查边缘服务器http://localhost:8765/actuator/mappings - 我在这里演示了最感兴趣的部分):

{
  "contexts": {
    "edge-server-1": {
      "mappings": {
        "dispatcherServlets": {
          "dispatcherServlet": [
            ...,
            {
              "handler": "org.springframework.cloud.netflix.zuul.web.ZuulController@24a37416",
              "predicate": "/card-service/**",
              "details": null
            },
Run Code Online (Sandbox Code Playgroud)

知道如何修复zuul 的路由映射吗?

Ser*_*gii 6

这是我的失败。我以为我已经按照教程对其进行了配置,但似乎使用@EnableZuulServer了自动完成功能而不是@EnableZuulProxySpring Boot 配置。@EnableZuulProxy需要routes为 Zuul加载配置,并且一切正常。