springcloud-服务注册consul客户端

1.版本说明

springboot 2.2.5.RELEASE

springcloud Hoxton.SR6

2.依赖

        <!--引入consul client依赖-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-consul-discovery</artifactId>
        </dependency>


        <!--
            注意:必须引入健康检查依赖,如果没有引入这个依赖,及时服务可用
             但是在consul服务注册中获取不到服务状态,consul注册中心始终认为不可用
             -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

 3.配置文件

server.port=8083
spring.application.name=consulclient

spring.cloud.consul.host=localhost
spring.cloud.consul.port=8500

spring.cloud.consul.discovery.register-health-check=true
spring.cloud.consul.discovery.service-name=${spring.application.name}

 4.启动注解

@SpringBootApplication
@EnableDiscoveryClient
public class ConsulclientApplication {

    public static void main(String[] args) {
        SpringApplication.run(ConsulclientApplication.class, args);
    }

}

 

posted @ 2020-08-08 11:50  陶海军  阅读(370)  评论(0编辑  收藏  举报