欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

spring cloud consul 配置中心

程序员文章站 2022-07-15 09:48:25
...

spring cloud consul 配置中心

 

spring cloud使用consul可以实现动态配置

 

****************************************************

引入jar包

 

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

 

*****************************************************

bootstrap.yml

 

spring:
  application:
    name: hello-service2
  profiles:
    active: dev
  cloud:
    consul:
      host: 192.168.57.120
      port: 8501
      config:
        format: yaml
        prefix: config
        profile-separator: "::"
        data-key: data

 

*************************************************

pojo 层

 

@Data
@Configuration
@ConfigurationProperties("person")
public class Person implements Serializable {

    private String name;
    private Integer age;
}

 

************************************************

控制层输出

           spring cloud consul 配置中心

 

                   spring cloud consul 配置中心

 

             spring cloud consul 配置中心

 

                               spring cloud consul 配置中心