Zuul和Consul整合问题 [英] Zuul and Consul integration issue

查看:618
本文介绍了Zuul和Consul整合问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have problem setting up Spring Cloud application with Zuul and Consul service discovery. I have Consul server agent installed and running locally:

./src/main/bash/local_run_consul.sh

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

When I run Spring Boot application with @EnableZuulProxy annotation I get the following error:

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中正确注册.

Note: When I comment out the @EnableZuulProxy annotation, my service runs without problems and is registered in Consul correctly.

我不知道该怎么办.也许有一些严重的依赖性问题?

I have no idea what to do. Maybe there is some bad dependency issue?

提前谢谢.

推荐答案

有一个ConsulDiscoveryClient.getLocalServiceInstance在spring-cloud-consul中进行nofollow> bug .

There is a bug in spring-cloud-consul with ConsulDiscoveryClient.getLocalServiceInstance.

设置zuul.ignoreLocalService: false暂时可以解决该问题.

Setting zuul.ignoreLocalService: false will work around it for now.

这篇关于Zuul和Consul整合问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆