本文主要是介绍【SpringCloud深入浅出系列】SpringCloud组件之集成Config实现本地配置中心,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
SpringCloud 组件之集成 Config 实现本地配置中心
- 一、项目说明
- 二、实现本地配置中心
- 1.创建配置文件
- 2.添加配置
- 3.启动测试
一、项目说明
之前已经在 SpringCloud 组件之集成Config实现分布式配置 文中实现了 Config 的分布式配置,通过读取 Gitee 远程仓库的方式获取配置信息,本文在该项目的基础上对代码进行修改,实现通过读取本地物理路径获取配置信息。
二、实现本地配置中心
主要是对 config-server 端进行修改。
1.创建配置文件
在 src/main/resources 目录下创建 yml 目录,并创建 3 个 yml 文件:
2.添加配置
修改 application.yml 文件,添加 native 相关配置,完整配置如下(其中 git 相关配置可去掉):
server:port: 8081spring:profiles:active: native #使用本地存储application:name: config-servercloud:config:server:git:uri: https://gitee.com/*******/springcloud-config.git # 仓库链接search-paths:- springcloud-configusername: ***********password: ***********default-label: masternative:search-locations: classpath:yml/ #搜索 src/main/resources 下的 yml 目录下的文件label: mastereureka:client:serviceUrl: #注册中心注册地址defaultZone: http://127.0.0.1:8080/eureka/
3.启动测试
启动服务后,浏览器输入:http://localhost:8082/configInfo 和 http://localhost:8082/configInfo,显示以下信息说明配置成功:
这篇关于【SpringCloud深入浅出系列】SpringCloud组件之集成Config实现本地配置中心的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!