spring cloud config 高可用配置
来源:互联网 发布:防伪码生成软件 编辑:程序博客网 时间:2024/05/16 09:56
spring cloud config
spring cloud 的配置管理中心,用来统一管理各个微服务的配置文件的。分为服务端和客户端 ,下面直接上代码为大家建立一个config-server config-client
创建项目 bw-config-server
1.bootstrap.yml
server: port: 8084eureka: client: service-url: defaultZone: http://localhost:1111/eureka/ #自己创建好的eureka-serverspring: application: name: config-server cloud: config: server: git: uri: https://gitee.com/*****/config.git #git仓库的地址 searchPaths: bw* #搜索的文件夹名字 注意区分 search-paths username: username password: password
2 pom.xml
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId></dependency><dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency>
3启动类
@SpringBootApplication@EnableConfigServer@EnableDiscoveryClientpublic class BwConfigServerApplication { public static void main(String[] args) { SpringApplication.run(BwConfigServerApplication.class, args); }}
这样一个config-server 创建完成,在创建之前要在git上面创建一个项目,config/ bw-sms文件夹下 bw-sms-dev.properties
创建一个bw-sms
跟普通的springBoot项目基本一样
1.bootstrop.yml
server: port: 8083eureka: client: service-url: defaultZone: http://localhost:1111/eureka/spring: application: name: bw-sms cloud: config: discovery: enabled: true #作为config client 去发现服务 service-id: config-server profile: dev label: master
2.pom.xml
<!-- eureka客户端依赖 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> </dependency> <!-- config客户端依赖 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency>
3.启动类
@SpringBootApplication
@EnableDiscoveryClient
public class BwSmsApplication {
public static void main(String[] args) { SpringApplication.run(BwSmsApplication.class, args);}
}
这样就完成了一个简单的客户端
测试的话自己随便写一个 测试一下就可以
@value(“${value}”)
private String value;`
总结一下我在做这个的时候遇到的坑;
1.配置文件的名字 要用bootstrap.yml 不能用application.yml或者application.properties,原因bootstrap的加载顺序先于application,所以要在application加载之前 指定application的位置;
2.在配置 配置文件搜索路径的时候注意区分
searchPaths: bw* #搜索的 以bw开通的文件
search-paths: /config #搜索的路径 在config文件夹下面的文件
3.检测配置中心config-server 是否配置正确可以通过访问
http://localhost:8084/bw-sms/dev
得到下面内容
<Environment><name>bw-sms</name><profiles><profiles>dev</profiles></profiles><label/><version>1ffe10c7bf4e89dbec74fdfca004e5757acddf10</version><state/><propertySources><propertySources><name>https://gitee.com/shanshaowei/config.git/bw-sms/bw-sms-dev.properties</name><source><content>success</content><title>success11222222</title><id>12</id></source></propertySources></propertySources></Environment>
- spring cloud config 高可用配置
- spring cloud config分布式配置中心的高可用
- SpringCloud: 高可用的分布式配置中心(Spring Cloud Config)
- Spring Cloud入门之Spring Cloud Config(高可用,刷新配置)
- Spring Cloud(八)高可用的分布式配置中心 Spring Cloud Config
- Spring Cloud(九)高可用的分布式配置中心 Spring Cloud Config 集成 Eureka 服务
- Spring Cloud(十)高可用的分布式配置中心 Spring Cloud Config 中使用 Refresh
- 史上最简单的SpringCloud教程 | 第七篇: 高可用的分布式配置中心(Spring Cloud Config)
- 史上最简单的SpringCloud教程 | 第七篇: 高可用的分布式配置中心(Spring Cloud Config)
- 史上最简单的SpringCloud教程 | 第七篇: 高可用的分布式配置中心(Spring Cloud Config)
- 史上最简单的SpringCloud教程 | 第七篇: 高可用的分布式配置中心(Spring Cloud Config)
- 史上最简单的SpringCloud教程 | 第七篇: 高可用的分布式配置中心(Spring Cloud Config)
- 史上最简单的SpringCloud教程 | 第七篇: 高可用的分布式配置中心(Spring Cloud Config)
- 史上最简单的SpringCloud教程 | 第七篇: 高可用的分布式配置中心(Spring Cloud Config)
- 史上最简单的SpringCloud教程 | 第七篇: 高可用的分布式配置中心(Spring Cloud Config)
- 第七篇: 高可用的分布式配置中心(Spring Cloud Config)
- SpringCloud教程 | 第七篇: 高可用的分布式配置中心(Spring Cloud Config)
- spring-cloud中config配置中心使用(基于eureka的高可用)
- 程序员面试失败的几种原因
- 平安圣诞程序员如何约到女神,和女神嘿嘿嘿!!!
- Python基础只是之什么是python
- 同事代码写的乱怎么办?
- 如何让微信官方给你加圣诞帽
- spring cloud config 高可用配置
- ctf-----这个看起来有点简单
- [SAP]各个系统平台设置library.path
- 语言模型评价指标Perplexity
- 十大免费SSL证书:网站免费添加HTTPS加密
- easybcd添加ubuntu启动项方法教程
- Mac网卡命令行
- 自然语言处理怎么最快入门?
- 洛谷P3567 [POI2014]KUR-Couriers(BZOJ3524)