簡體   English   中英

spring-boot客戶端無法從領事開始

[英]spring-boot client unable to start with consul

我使用以下命令在我的系統上使用docker設置並運行consul:

sudo docker run -p 8500:8500 consul:0.9.2

領事運行正常,可以從領事UI進行檢查(下面的圖片):

在此處輸入圖片說明

現在,我嘗試運行我的spring-boot服務,以使用該領事實例進行服務發現和注冊。 但是,無論何時啟動,它都會給我以下異常:

2017-09-02 18:58:17.091 ERROR 5578 --- [  restartedMain] o.s.c.c.c.ConsulPropertySourceLocator    : Fail fast is set and there was an error reading configuration from consul.
2017-09-02 18:58:18.183 ERROR 5578 --- [  restartedMain] o.s.c.c.c.ConsulPropertySourceLocator    : Fail fast is set and there was an error reading configuration from consul.
2017-09-02 18:58:19.375 ERROR 5578 --- [  restartedMain] o.s.c.c.c.ConsulPropertySourceLocator    : Fail fast is set and there was an error reading configuration from consul.
2017-09-02 18:58:20.691 ERROR 5578 --- [  restartedMain] o.s.c.c.c.ConsulPropertySourceLocator    : Fail fast is set and there was an error reading configuration from consul.
2017-09-02 18:58:22.114 ERROR 5578 --- [  restartedMain] o.s.c.c.c.ConsulPropertySourceLocator    : Fail fast is set and there was an error reading configuration from consul.
2017-09-02 18:58:23.671 ERROR 5578 --- [  restartedMain] o.s.c.c.c.ConsulPropertySourceLocator    : Fail fast is set and there was an error reading configuration from consul.
2017-09-02 18:58:23.691 ERROR 5578 --- [  restartedMain] o.s.boot.SpringApplication               : Application startup failed

com.ecwid.consul.v1.OperationException: OperationException(statusCode=500, statusMessage='Internal Server Error', statusContent='No cluster leader')
    at com.ecwid.consul.v1.kv.KeyValueConsulClient.getKVValues(KeyValueConsulClient.java:159)
    at com.ecwid.consul.v1.ConsulClient.getKVValues(ConsulClient.java:487)
    at org.springframework.cloud.consul.config.ConsulPropertySource.init(ConsulPropertySource.java:66)
    at org.springframework.cloud.consul.config.ConsulPropertySourceLocator.create(ConsulPropertySourceLocator.java:157)
    at org.springframework.cloud.consul.config.ConsulPropertySourceLocator.locate(ConsulPropertySourceLocator.java:131)
    at org.springframework.cloud.consul.config.ConsulPropertySourceLocator$$FastClassBySpringCGLIB$$b35ebf8.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.retry.interceptor.RetryOperationsInterceptor$1.doWithRetry(RetryOperationsInterceptor.java:91)
    at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:286)
    at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:163)
    at org.springframework.retry.interceptor.RetryOperationsInterceptor.invoke(RetryOperationsInterceptor.java:118)
    at org.springframework.retry.annotation.AnnotationAwareRetryOperationsInterceptor.invoke(AnnotationAwareRetryOperationsInterceptor.java:152)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673)
    at org.springframework.cloud.consul.config.ConsulPropertySourceLocator$$EnhancerBySpringCGLIB$$66375879.locate(<generated>)
    at org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.initialize(PropertySourceBootstrapConfiguration.java:93)
    at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:567)
    at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:338)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:301)
    at com.pyg.auth.AuthServiceApp.main(AuthServiceApp.java:71)
    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:498)
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)

SpringBoot Main Class可以很好地注釋(我想),因為我的spring-boot服務可以與先前的另一個領事實例一起正常工作。

我可以通過將領事服務器和端口配置從application.yml移到bootstrap.yml來解決我的問題。

我對如何解決它以及為什么無法從application.yml中讀取信息了解不多。 如果有人對此有一些細節,請。 讓我知道。

使用sudo docker run -p 8500:8500 consul:0.9.2 -bootstrap解決此問題。 我添加了-bootstrap一個參數來引導服務器,並被選為領導者。

在Consul的新版本(0.5和更高版本)中,不建議使用-bootstrap進行手動引導,因為它更容易出錯。

說明:-

docs中所述, 在Consul群集可以開始處理請求之前,必須選擇服務器節點的領導者。 這是您在啟動春季啟動服務時出現例外的原因,領導者尚未當選!!

為什么領導人沒有當選? 群集中涉及的服務器列表應被引導。 可以使用-bootstrap-expect配置選項來引導服務器。 推薦的

注意:-僅出於測試/學習目的,您可以繼續創建單個服務器,因為強烈建議不要部署單個服務器,因為在故障情況下不可避免地會丟失數據。

檢查您的pom.xml。

不要使用spring-cloud-starter-consul-all 請改用spring-cloud-starter-consul-discovery

那對我有用。

請檢查pom.xml以避免使用spring-cloud-starter-consul-all如果使用spring-cloud-starter-consul-all,請將該配置寫入bootstrap.yml,bootstrap.yml配置文件是第一個加載的文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM