最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
SpringCloud配置中心Config过程代码解析
时间:2020-03-17 编辑:袖梨 来源:一聚教程网
本篇文章小编给大家分享一下SpringCloud配置中心Config过程代码解析,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。
1.什么是配置中心
统一管理配置,怏速切换各个环境的配置
2.添加依赖
org.springframework.cloud spring-cloud-config-server org.springframework.cloud spring-cloud-starter-netflix-eureka-client
3.启动类添加注解@EnableConfigServer
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.config.server.EnableConfigServer; @SpringBootApplication @EnableConfigServer public class ConfigServiceApplication { public static void main(String[] args) { SpringApplication.run(ConfigServiceApplication.class, args); } }
4.修改application.yml配置
server: port: 9100 eureka: client: serviceUrl: defaultZone: http://localhost:8761/eureka/ spring: application: name: config-server cloud: config: server: git: #仓库地址,去掉git uri: https://gitee.com/YTHeng/config_cloud #git服务器登录的用户名和密码,我这边使用的是码云 username: 12345678@qq.com password: 12345678. #超时时间 timeout: 5 #分支 default-label: master
5.在码云服务器新建仓库和文件
6.访问地址
http://localhost:9100/master/product-service-dev.yml
路径访问方式
/{name}-{profiles}. properties
/{name}-{profiles}.yml
/{name}-{profiles}.json
/{label}/{name]-{profiles].yml
name:服务器名称
profile:环境名称,开发、测试、生产
Lable:仓库分支、默认 master分支
另附:
相关文章
- SpringBoot自定义bean绑定解析 10-24
- Javaweb工程运行报错HTTP Status 404解决教程 10-20
- JAVA获取jvm和操作系统相关信息方法 10-20
- BeanFactory和FactoryBean的区别讲解 10-20
- 微信小程序的宿主环境实现教程 10-10
- dispatchEvent解决重叠元素响应事件教程 10-10