共计 1734 个字符,预计需要花费 5 分钟才能阅读完成。
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 |
正文完
星哥玩云-微信公众号
