组团学

用Git配置"配置服务器"

阅读 (939290)

1、用Git配置"配置服务器"

1.1、在Git仓库中创建配置文件

1.1.1、在本地新建两个配置文件"config-dev.properties"和"config-pro.properties"

在config-dev.properites文件中写入以下内容:

app.version=dev
message=Spring Cloud Config
spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
server.port=50028

在config-pro.properties文件中写入以下内容:

app.version=pro
message=Spring Cloud Config
spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
server.port=50029

1.1.2、上传新建的两个配置文件到自己的Git仓库地址

1.2、读取配置信息

1.2.1、访问:http://localhost:50027/config/dev

{"name":"config","profiles":["dev"],"label":null,"version":"00f8179acc9ad109abc114309d8e46a0b032aa14","state":null,"propertySources":[{"name":"https://github.com/lingfengxeon/spring-config/config-dev.properties","source":{"app.version":"dev","message":"Spring Cloud Config","spring.rabbitmq.host":"localhost","spring.rabbitmq.port":"5672","spring.rabbitmq.username":"guest","spring.rabbitmq.password":"guest","server.port":"50028"}}]}

1.2.2、访问:http://localhost:50027/config/pro

{"name":"config","profiles":["pro"],"label":null,"version":"00f8179acc9ad109abc114309d8e46a0b032aa14","state":null,"propertySources":[{"name":"https://github.com/lingfengxeon/spring-config/config-pro.properties","source":{"app.version":"pro","message":"Spring Cloud Config","spring.rabbitmq.host":"localhost","spring.rabbitmq.port":"5672","spring.rabbitmq.username":"guest","spring.rabbitmq.password":"guest","server.port":"50029"}}]}

1.2.3、读取Config Server的配置信息

访问:http://localhost:50027/config-dev.properties

app.version: dev
message: Spring Cloud Config
server.port: 50028
spring.rabbitmq.host: localhost
spring.rabbitmq.password: guest
spring.rabbitmq.port: 5672
spring.rabbitmq.username: guest

需要 登录 才可以提问哦