我有一个运行正常的 Eureka 服务器和一个连接到它的服务。
现在,我正在尝试将 Zuul 服务器连接到 Eureka,但它不起作用。
我这样配置 Zuul:

zuul:
  ignoredServices: "*"
  routes:
    contacts-service:
      path: /contacts/**
      serviceId: contacts-service

eureka:
  instance:
    preferIpAddress: true
  client:
    serviceUrl:
      defaultZone: http://eureka:[email protected]:8761/eureka/

和我的类(class)
@SpringBootApplication
@EnableZuulServer
@EnableDiscoveryClient
public class EdgeApplication {

    public static void main(String[] args) {
        SpringApplication.run(EdgeApplication.class, args);
    }
}

它从未在 Eureka 中显示,也没有在与 Eureka 相关的 zuul 日志中显示。好像我还缺少一些东西。

编辑

当我更改为 @EnableZuulProxy 时,出现错误并且 zuul 服务仍未显示在 Eureka 服务器上
2016-10-06 23:26:46.574  WARN 8303 --- [nio-8080-exec-3] o.s.c.n.z.filters.post.SendErrorFilter   : Error during filtering

com.netflix.zuul.exception.ZuulException: Forwarding error
    at org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.handleException(RibbonRoutingFilter.java:164) ~[spring-cloud-netflix-core-1.2.0.RELEASE.jar:1.2.0.RELEASE]
    at org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.forward(RibbonRoutingFilter.java:139) ~[spring-cloud-netflix-core-1.2.0.RELEASE.jar:1.2.0.RELEASE]
    at org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.run(RibbonRoutingFilter.java:84) ~[spring-cloud-netflix-core-1.2.0.RELEASE.jar:1.2.0.RELEASE]
    at com.netflix.zuul.ZuulFilter.runFilter(ZuulFilter.java:112) ~[zuul-core-1.2.2.jar:1.2.2]
    at com.netflix.zuul.FilterProcessor.processZuulFilter(FilterProcessor.java:197) ~[zuul-core-1.2.2.jar:1.2.2]
    at com.netflix.zuul.FilterProcessor.runFilters(FilterProcessor.java:161) ~[zuul-core-1.2.2.jar:1.2.2]
    at com.netflix.zuul.FilterProcessor.route(FilterProcessor.java:120) ~[zuul-core-1.2.2.jar:1.2.2]
    at com.netflix.zuul.ZuulRunner.route(ZuulRunner.java:96) ~[zuul-core-1.2.2.jar:1.2.2]
    at com.netflix.zuul.http.ZuulServlet.route(ZuulServlet.java:116) ~[zuul-core-1.2.2.jar:1.2.2]
    at com.netflix.zuul.http.ZuulServlet.service(ZuulServlet.java:81) ~[zuul-core-1.2.2.jar:1.2.2]
    at org.springframework.web.servlet.mvc.ServletWrappingController.handleRequestInternal(ServletWrappingController.java:157) [spring-webmvc-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.cloud.netflix.zuul.web.ZuulController.handleRequestInternal(ZuulController.java:43) [spring-cloud-netflix-core-1.2.0.RELEASE.jar:1.2.0.RELEASE]

编辑 2

有时,我会在 Eureka 服务器日志中看到这一点(不确定它是否与我的问题有关,tho):
2016-10-06 23:52:32.824 ERROR 7053 --- [et_localhost-14] c.n.e.cluster.ReplicationTaskProcessor   : Batch update failure with HTTP status code 401; discarding 1 replication tasks
2016-10-06 23:52:32.825  WARN 7053 --- [et_localhost-14] c.n.eureka.util.batcher.TaskExecutors    : Discarding 1 tasks of TaskBatchingWorker-target_localhost-14 due to permanent error
2016-10-06 23:52:38.279  INFO 7053 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry  : Running the evict task with compensationTime 1ms

在我调用 `/contacts/端点后,我在 zuul 代理日志中看到了这一点:
2016-10-06 23:52:50.256  INFO 9346 --- [nio-8080-exec-1] c.n.u.concurrent.ShutdownEnabledTimer    : Shutdown hook installed for: NFLoadBalancer-PingTimer-contacts-service
2016-10-06 23:52:50.309  INFO 9346 --- [nio-8080-exec-1] c.netflix.loadbalancer.BaseLoadBalancer  : Client:contacts-service instantiated a LoadBalancer:DynamicServerListLoadBalancer:{NFLoadBalancer:name=contacts-service,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:null
2016-10-06 23:52:50.316  INFO 9346 --- [nio-8080-exec-1] c.n.l.DynamicServerListLoadBalancer      : Using serverListUpdater PollingServerListUpdater
2016-10-06 23:52:50.322  INFO 9346 --- [nio-8080-exec-1] c.n.l.DynamicServerListLoadBalancer      : DynamicServerListLoadBalancer for client contacts-service initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=contacts-service,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:com.netflix.loadbalancer.ConfigurationBasedServerList@29851ac8
2016-10-06 23:52:50.785  WARN 9346 --- [nio-8080-exec-1] o.s.c.n.z.filters.post.SendErrorFilter   : Error during filtering

最佳答案

您在 zuul 服务中缺少以下依赖项:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>

关于spring-cloud - Zuul 无法连接到 Eureka,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39905509/

10-11 10:43