美文网首页
springboot2.X整合consul

springboot2.X整合consul

作者: EnumaElish666 | 来源:发表于2019-12-27 14:44 被阅读0次

    1.添加依赖

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-actuator</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-consul-discovery</artifactId>
            </dependency>
    

    2.在主入口程序类上增加 @EnableDiscoveryClient 注解

    @SpringBootApplication
    @EnableDiscoveryClient
    public class SvcProducerApplication {
        public static void main(String[] args) {
            SpringApplication.run(SvcProducerApplication.class, args);
        }
    }
    

    添加Consul配置

    #Consul配置
    #Consul配置
    ## 192.168.2.215
    spring.cloud.consul.host=agent
    spring.cloud.consul.port=8500
    spring.cloud.consul.discovery.healthCheckUrl=http://localhost:${server.port}/health
    spring.cloud.consul.discovery.instance-id=${spring.application.name}:${server.port}:${random.value}
    spring.cloud.consul.discovery.hostname=agent
    spring.cloud.consul.discovery.healthCheckInterval=5s
    spring.cloud.consul.discovery.prefer-ip-address=true
    spring.cloud.consul.discovery.enabled=true
    spring.cloud.consul.discovery.heartbeat.enabled=true
    spring.cloud.consul.discovery.register = true
    spring.cloud.consul.discovery.register-health-check = true
    spring.cloud.service-registry.auto-registration.enabled=true
    

    相关文章

      网友评论

          本文标题:springboot2.X整合consul

          本文链接:https://www.haomeiwen.com/subject/flrdoctx.html