【问题标题】:Zuul and Consul integration issueZuul 和 Consul 集成问题
【发布时间】:2016-02-20 08:31:00
【问题描述】:

我在使用 Zuul 和 Consul 服务发现设置 Spring Cloud 应用程序时遇到问题。我已在本地安装并运行 Consul 服务器代理:

./src/main/bash/local_run_consul.sh

当我使用 @EnableZuulProxy 注释运行 Spring Boot 应用程序时,我收到以下错误:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.netflix.zuul.filters.RouteLocator]: Factory method 'routeLocator' threw exception; nested exception is java.lang.IllegalStateException: Unable to locate service in consul agent: edge-server-8765
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
    ... 73 more

来源:

build.gradle

buildscript {
    ext {
        springBootVersion = '1.2.7.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'war'
apply plugin: 'spring-boot'

war {
    baseName = 'edge-server'
    version = '0.0.1-SNAPSHOT'
}

mainClassName = 'com.akamai.pulsar.onboarding.edge.app.ZuulApplication'

dependencies {
    providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")

    compile("org.springframework.boot:spring-boot-starter-web") {
        exclude module: 'spring-boot-starter-tomcat'
    }
    compile("org.springframework.boot:spring-boot-starter-undertow")
    compile("org.springframework.boot:spring-boot-starter-actuator")
    compile('org.springframework.cloud:spring-cloud-starter-zuul:1.0.0.RELEASE')
    compile('org.springframework.cloud:spring-cloud-starter-consul-all:1.0.0.M3')

    testCompile('org.springframework.boot:spring-boot-starter-test')
}

application.yml

info:
  component: Zuul Server

endpoints:
  restart:
    enabled: true
  shutdown:
    enabled: true
  health:
    sensitive: false

zuul:
  ignoredServices: "*"
  routes:
    test-api:
      path: /test-api/**

server:
  port: 8765

logging:
  level:
    ROOT: INFO
    org.springframework.web: INFO

bootstrap.yml

spring:
  application:
    name: edge-server
  cloud:
    consul:
      host: localhost
      port: 8500
      config:
        enabled: true

ZuulApplication.java

@SpringBootApplication
@EnableDiscoveryClient
@EnableZuulProxy
public class ZuulApplication {

    public static void main(String[] args) {
        new SpringApplicationBuilder(ZuulApplication.class).web(true).run(args);
    }
}

注意:当我注释掉 @EnableZuulProxy 注释时,我的服务运行没有问题,并且在 Consul 中正确注册。

我不知道该怎么做。也许有一些糟糕的依赖问题?

提前致谢。

【问题讨论】:

  • spring-cloud-consul 是为 spring-boot 1.3.x 构建的,这可能是个问题。我会试一试。
  • 可以使用的 spring-cloud-zuul 版本是 1.1.0.M4

标签: spring spring-cloud consul netflix-zuul


【解决方案1】:

spring-cloud-consul 中有一个bugConsulDiscoveryClient.getLocalServiceInstance

设置 zuul.ignoreLocalService: false 现在可以解决它。

【讨论】:

  • 这已在快照中修复。
  • 非常感谢@spencergibb 您的解决方案是正确的。
猜你喜欢
  • 2017-09-18
  • 1970-01-01
  • 1970-01-01
  • 2015-09-08
  • 1970-01-01
  • 2017-08-28
  • 2016-06-05
  • 2016-02-25
  • 2018-07-28
相关资源
最近更新 更多