我使用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
时,我正在使用Map
来获取 eureka.client.serviceUrl 。
但我实际上正在使用Map
和键值对defaultZone: http://user:password@172.31.7.240:8762/eureka/
。
有没有人之前看过这样的例外,可以告诉我我做错了什么?正如我所知道的那样,我使用的语法与Spring文档中使用的语法完全相同。
修改
我刚刚更新到Spring Boot 1.2.3.RELEASE和Spring Cloud Netflix 1.0.1.RELEASE,所以我应该使用最新版本。
答案 0 :(得分:2)
在评论形式@DaveSyer后想出来。
实际上还有其他属性来源:环境变量。名为EUREKA_CLIENT_SERVICE_URL
的变量被定义为无意中覆盖了YAML中的配置。删除/重命名此变量后,一切都开始工作。