2015-04-28 91 views
2

我使用Spring Cloud Netflix構建Eureka服務器。服務器正在運行,因此我正在嘗試添加第二臺Eureka服務器以提高彈性,並在更新服務器時提供備用服務器。爲Spring Cloud設置基於Netflix的Eureka服務器的對等意識

http://cloud.spring.io/spring-cloud-netflix/spring-cloud-netflix.html使這聽起來很容易:你只需要配置你的服務器,像Eureka客戶端自己。所以我添加到我的bootstrap.yml配置客戶端:

eureka: 
    client: 
     serviceUrl: 
      defaultZone: http://user:[email protected]:8762/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:[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) 

很顯然,我的網址實際上是從配置讀取(在它出現在例外)。但它看起來像不正確的分析。異常告訴我,我使用的Stringeureka.client.serviceUrl當我應該使用Map。 但我實際上使用Map與鍵值對defaultZone: http://user:[email protected]:8762/eureka/

有沒有人看到過這樣的例外,並可以告訴我我做錯了什麼?就像我可以告訴的那樣,我使用的是與Spring文檔中使用的完全相同的語法。

編輯:

我剛剛更新到春季啓動1.2.3.RELEASE和Spring雲Netflix的1.0.1.RELEASE所以我應該使用最新的版本。

+0

YAML中的空白錯誤? –

+1

其實我不認爲這個錯誤與你發佈的YAML有關。 YAML是錯誤的還是你有其他財產來源有不良的價值? –

+0

@DaveSyer感謝您的意見。 YAML中的空白是我檢查的第一件事情之一,因爲這是一個常見問題。我剛剛在本地啓動應用程序,一切正常。 (我無法解釋爲什麼我昨天沒有嘗試這個......)所以這個問題很可能與它如何使用Ansible進行部署。對不起。我犯傻了。 :d –

回答

0

在評論表單@DaveSyer後顯示出來。

實際上有一個其他屬性來源:環境變量。名爲EUREKA_CLIENT_SERVICE_URL的變量被定義爲無意覆蓋YAML中的配置。我刪除/重命名這個變量後,一切開始工作。

相關問題