Reputation: 1641
I build a Eureka server using Spring Cloud Netflix. The server is working so I am currently trying to add a second Eureka Server to improve resilience and provide a fallback server when updating the server.
http://cloud.spring.io/spring-cloud-netflix/spring-cloud-netflix.html makes this sound pretty easy: You just have to config your server like Eureka clients themselves. So I added to my bootstrap.yml configuration for the client:
eureka:
client:
serviceUrl:
defaultZone: http://user:[email protected]:8762/eureka/
As far as I can tell this is identical to the config currently used by my other eureka clients. So I assumed this would work. But instead I get a strange exception:
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:[email protected]: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:[email protected]: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)
It is clear that my URL is actually read from the configuration (at it appears in the exception). But it looks like it is parsed incorrectly. The exception tells me I am using a String
for eureka.client.serviceUrl when I should use a Map
.
But I am in fact using a Map
with the key-value pair defaultZone: http://user:[email protected]:8762/eureka/
.
Has anybody seen a exception like this before and can tell me what I am doing wrong? As fat as I can tell I am using exactly the same syntax as is used in the Spring documentation.
Edit:
I just updated to Spring Boot 1.2.3.RELEASE and Spring Cloud Netflix 1.0.1.RELEASE so I should be using the latest version.
Upvotes: 2
Views: 2792
Reputation: 1641
Figured it out after the comments form @DaveSyer.
There was in fact an other property source: Environment variables. A variable named EUREKA_CLIENT_SERVICE_URL
was defined unintentional overwriting the configuration from the YAML. After I removed/renames this variable everything started working.
Upvotes: 2