2

我使用 Spring Cloud Netflix 构建了一个 Eureka 服务器。服务器正在运行,因此我目前正在尝试添加第二个 Eureka 服务器以提高弹性并在更新服务器时提供备用服务器。

http://cloud.spring.io/spring-cloud-netflix/spring-cloud-netflix.html让这听起来很简单:你只需要像 Eureka 客户端一样配置你的服务器。所以我为客户端添加了我的bootstrap.yml配置:

eureka:
    client:
        serviceUrl:
            defaultZone: http://user:password@172.31.7.240:8762/eureka/

据我所知,这与我的其他 eureka 客户端当前使用的配置相同。所以我认为这会奏效。但相反,我得到了一个奇怪的例外:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'discoveryManagerIntitializer': Injection of autowired dependencies failed; nested exception is     org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.netflix.discovery.EurekaClientConfig org.springframework.cloud.netflix.eureka.DiscoveryManagerInitializer.clientConfig; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'eurekaClientConfigBean': Could not bind properties to [unknown] (target=eureka.client, ignoreInvalidFields=false, ignoreUnknownFields=true, ignoreNestedProperties=false); nested exception is org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 2 errors
Field error in object 'eureka.client' on field 'serviceUrl': rejected value [http://user:password@172.31.7.240:8762/eureka/]; codes [typeMismatch.eureka.client.serviceUrl,typeMismatch.serviceUrl,typeMismatch.java.util.Map,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [eureka.client.serviceUrl,serviceUrl]; arguments []; default message [serviceUrl]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Map' for property 'serviceUrl'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [java.util.Map] for property 'serviceUrl': no matching editors or conversion strategy found]
Field error in object 'eureka.client' on field 'serviceUrl': rejected value [http://user:password@172.31.7.240:8762/eureka/]; codes [typeMismatch.eureka.client.serviceUrl,typeMismatch.serviceUrl,typeMismatch.java.util.Map,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [eureka.client.serviceUrl,serviceUrl]; arguments []; default message [serviceUrl]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Map' for property 'serviceUrl'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [java.util.Map] for property 'serviceUrl': no matching editors or conversion strategy found]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1202)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:957)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:946)
    at com.emnos.registry.RegistryApplication.main(RegistryApplication.java:18)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
    at java.lang.Thread.run(Thread.java:745)

很明显,我的 URL 实际上是从配置中读取的(它出现在异常中)。但看起来它被错误地解析了。异常告诉我String,当我应该使用 a 时,我正在使用eureka.client.serviceUrlMap。但我实际上是在使用 aMap和 key-value pair defaultZone: http://user:password@172.31.7.240:8762/eureka/

有没有人见过这样的异常,可以告诉我我做错了什么?据我所知,我使用的语法与 Spring 文档中使用的语法完全相同。

编辑:

我刚刚更新到 Spring Boot 1.2.3.RELEASE 和 Spring Cloud Netflix 1.0.1.RELEASE,所以我应该使用最新版本。

4

1 回答 1

2

在@DaveSyer 的评论表之后想通了。

实际上还有另一个属性来源:环境变量。一个名为的变量EUREKA_CLIENT_SERVICE_URL被定义为无意覆盖来自 YAML 的配置。在我删除/重命名这个变量之后,一切都开始工作了。

于 2015-04-29T08:02:36.283 回答