我使用spring cloud consul作为注册服务,spring cloud config + git作为配置服务器。一个微服务应用程序使用consul发现配置服务器,然后通过propery密钥获取价值,也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获取值,也可以注册服务到consul成功,但是关闭app(control + C),ConsulLifecycle取消注册不执行。记录如下:
2016-08-05 13:22:59.675 INFO 86816 --- [ Thread-3] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@c00fff0: startup date [Fri Aug 05 13:22:43 CST 2016]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@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.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@52066604: startup date [Fri Aug 05 13:23:51 CST 2016]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@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
我不知道为什么,什么都有冲突?请转发任何答案 @spencergibb
答案 0 :(得分:0)
我遇到了同样的问题,并在github上的spring-cloud-consul上打开了一个问题:https://github.com/spring-cloud/spring-cloud-consul/issues/213