Springboot: 2.1.x: spring cloud config 中心的实践

随着分布式项目规模的扩大,配置文件管理变得复杂且繁琐。本文介绍如何使用SpringCloud Config作为配置中心,实现配置文件的统一管理和自动更新,提高开发效率。文章探讨了配置中心在大型分布式项目中的应用,以及SpringCloud Config与spring.profiles.active的区别,同时对比了QConf、diamond、disconf等配置中心解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

随着分布式项目越来越大,勤劳的程序猿们会开始面临一个挑战,配置文件会越来越繁杂,虽然spring提供了一个鸡肋版的解决方案,spring.profiles.active,在大型的分布式项目体系中,聊胜于无吧,手动维护配置文件的痛苦,生产,UAT,测试,开发环境的隔离,额外的配置文件,如:logback.xml日志的配置文件,bootstrap.properties配置文件,当系统中有几十个服务,相应的会有上百个配置文件,简直就是史诗级的灾难大片,每次发布上线,都要手动去检查配置文件,相应的服务都需要重启,那么,有没有一种方案,可以自动更新配置,并且对版本做出相应的控制,恰好,springcloud为我们提供了这样一种工具,虽然很多方面都还不完善,配置能力比较弱,但是也给我们提供了一种思路。

市面上有很多配置中心,BAT每家都出过,360的QConf、淘宝的diamond、百度的disconf都是解决这类问题。国外也有很多开源的配置中心Apache Commons Configuration、owner、cfg4j等等。这些开源的软件以及解决方案都很优秀,也存在这样或者那样的缺陷。今天我们要了解的Spring Cloud Config,可以无缝的和spring体系相结合,够方便够简单颜值高。

本实验的版本要求如下:

Springboot: 2.1.6.RELEASE
SpringCloud: Greenwich.SR1
JDK 8.x

如无特殊说明,本系列教程全采用以上版本。

推荐下面的几篇文章

  1. SpringCloudConfigGithub配置中心
  2. Spring Cloud Config 配置中心高可用和refresh
  3. Spring Cloud Bus 消息总线
2025-03-11 09:50:08.567 ERROR 3312 --- [ileListener_3_1] io.seata.config.FileConfiguration : fileListener execute error, dataId :service.vgroupMapping.tx_yulin_group java.lang.reflect.InvocationTargetException: null at sun.reflect.GeneratedMethodAccessor237.invoke(Unknown Source) ~[na:na] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_131] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_131] at io.seata.config.ConfigurationCache.lambda$proxy$1(ConfigurationCache.java:95) ~[seata-all-1.4.0.VENUS.jar:1.4.0.VENUS] at io.seata.config.Configuration$$EnhancerByCGLIB$$6985b4d8.getLatestConfig(<generated>) ~[cglib-3.1.jar:1.4.0.VENUS] at io.seata.config.FileConfiguration$FileListener.onChangeEvent(FileConfiguration.java:365) ~[seata-all-1.4.0.VENUS.jar:1.4.0.VENUS] at io.seata.config.ConfigurationChangeListener.lambda$onProcessEvent$0(ConfigurationChangeListener.java:62) [seata-all-1.4.0.VENUS.jar:1.4.0.VENUS] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[na:1.8.0_131] at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_131] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_131] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_131] at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-all-4.1.33.Final.jar:4.1.33.Final] at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_131] Caused by: java.lang.IllegalStateException: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@f679798 has not been refreshed yet at org.springframework.context.support.AbstractApplicationContext.assertBeanFactoryActive(AbstractApplicationContext.java:1092) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE] at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1122) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE] at io.seata.spring.boot.autoconfigure.provider.SpringBootConfigurationProvider.get(SpringBootConfigurationProvider.java:93) ~[seata-spring-boot-starter-1.4.0.jar:na] at io.seata.spring.boot.autoconfigure.provider.SpringBootConfigurationProvider.get(SpringBootConfigurationProvider.java:82) ~[seata-spring-boot-starter-1.4.0.jar:na] at io.seata.spring.boot.autoconfigure.provider.SpringBootConfigurationProvider.get(SpringBootConfigurationProvider.java:77) ~[seata-spring-boot-starter-1.4.0.jar:na] at io.seata.spring.boot.autoconfigure.provider.SpringBootConfigurationProvider.access$300(SpringBootConfigurationProvider.java:43) ~[seata-spring-boot-starter-1.4.0.jar:na] at io.seata.spring.boot.autoconfigure.provider.SpringBootConfigurationProvider$1.intercept(SpringBootConfigurationProvider.java:60) ~[seata-spring-boot-starter-1.4.0.jar:na] at io.seata.config.FileConfiguration$$EnhancerByCGLIB$$862af1eb.getLatestConfig(<generated>) ~[seata-all-1.4.0.VENUS.jar:1.4.0.VENUS] ... 13 common frames omitted
03-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值