一.概述
在第十章有中有提到,Spring Cloud Config是可以实现基于本地和远程两方式获取配置,基于远程git的配置我们已经玩过了之后,基于本地配置的Config就特别简单了,下面我们就来玩一下。
二.基于本地配置的Config Server
1.在原项目基础上修改ConfigServer项目的配置文件如下:
ring.cloud.config.server.native.search-locations=classpath:/shared spring.profiles.active=native spring.application.name=config-server server.port=5555ring.cloud.config.server.native.search-locations:本地配置文件路径
spring.profiles.active=native:指定使用本地配置方式
2.在resources目录中创建shared目录,并在shared中创建配置文件:config-client-dev.properties
```
notify=You are successful
server.port=7777
spring.profiles=dev
spring.application.name=config-dev
这里指定了一个 dev配置,端口为 7777 ,应用名为config-dev,和一个自定义的配置参数 notify
>3.修改ConfigClient项目的bootstrap.properties文件如下
spring.cloud.config.uri=http://localhost:5

本文介绍了Spring Cloud Config Server如何实现基于本地配置的设置。通过修改Config Server配置,指定`spring.profiles.active=native`启用本地配置,然后在resources共享目录下创建配置文件。当Config Client启动时,它会从Config Server获取相应的配置文件,如`config-client-dev.properties`,并根据配置信息进行环境切换。测试表明,Config Client成功读取配置并响应。
最低0.47元/天 解锁文章
947

被折叠的 条评论
为什么被折叠?



