0
我使用spring雲領事作爲註冊服務,spring cloud config + git作爲配置服務器。一個微服務應用程序使用consul發現configserver,然後通過propery key來獲取價值,另外app需要註冊服務給其他消費者調用。春季雲領事撤銷註冊因使用春季雲配置而退出失敗
依賴的pom.xml:
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<version>Brixton.SR4</version>
<relativePath/>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-consul-dependencies</artifactId>
<version>1.0.2.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
</dependency>
bootstarp.yml:
cloud:
config:
enabled: true
label: master
name: demo
discovery:
enabled: true
serviceId: CONFIG-SERVER
consul:
host: localhost
port: 8500
enabled: true
discovery:
enabled: true
healthCheckPath: /health
healthCheckInterval: 10s
tags: dev
應用程序啓動後的成功,可以從關鍵configserver獲得價值,還註冊服務領事成功,但關閉的應用程序(控制+ C),ConsulLifecycle註銷不會被執行。日誌如下:
2016-08-05 13:22:59.675 INFO 86816 --- [ Thread-3] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot[email protected]c00fff0: startup date [Fri Aug 05 13:22:43 CST 2016]; parent: org.spring[email protected]6989da5e
2016-08-05 13:22:59.678 INFO 86816 --- [ Thread-3] o.s.c.support.DefaultLifecycleProcessor : Stopping beans in phase 0
2016-08-05 13:22:59.684 INFO 86816 --- [ Thread-3] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
2016-08-05 13:22:59.685 INFO 86816 --- [ Thread-3] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans
所以我刪除依賴關係如下,重新啓動應用程序和關機,服務註銷成功。但無法獲取配置屬性。
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
2016-08-05 13:24:03.671 INFO 86820 ationConfigEmbeddedWebApplicationContext - Closing org.springframework.boot[email protected]52066604: startup date [Fri Aug 05 13:23:51 CST 2016]; parent: org.spring[email protected]3315d2d7
2016-08-05 13:24:03.674 INFO 86820 o.s.c.support.DefaultLifecycleProcessor - Stopping beans in phase 0
2016-08-05 13:24:03.675 INFO 86820 o.s.c.consul.discovery.ConsulLifecycle - Deregistering service with consul: demo-server-ed3e50ef60d3f5b1295f4866c46386d1
2016-08-05 13:24:03.777 INFO 86820 o.s.b.a.e.jmx.EndpointMBeanExporter - Unregistering JMX-exposed beans on shutdown
2016-08-05 13:24:03.785 INFO 86820 o.s.b.a.e.jmx.EndpointMBeanExporter - Unregistering JMX-exposed beans
2016-08-05 13:24:03.786 INFO 86820 o.s.j.e.a.AnnotationMBeanExporter - Unregistering JMX-exposed beans on shutdown
2016-08-05 13:24:03.787 INFO 86820 o.s.j.e.a.AnnotationMBeanExporter - Unregistering JMX-exposed beans
我不知道爲什麼,什麼是衝突?看轉發到任何回答,THKS @spencergibb