上一章介绍了disconf的安装预配置,这章主要介绍下disconf与spring集成

1、添加依赖

<dependency>
<groupId>com.baidu.disconf</groupId>
<artifactId>disconf-client</artifactId>
<version>2.6.36</version>
</dependency>

2、修改配置文件

修改spring的配置文件spring-config.xml

添加初始化配置

<!-- 使用disconf必须添加以下配置 -->
<bean id="disconfMgrBean" class="com.baidu.disconf.client.DisconfMgrBean"
destroy-method="destroy">
<property name="scanPackage" value="com.abcde" />
</bean>
<bean id="disconfMgrBean2" class="com.baidu.disconf.client.DisconfMgrBeanSecond"
init-method="init" destroy-method="destroy">
</bean>
<!-- 自动完成创建代理织入切面 -->
<aop:aspectj-autoproxy />

增加一个disconf.properties配置文件到classpath下:

# 是否使用远程配置文件
# true(默认)会从远程获取配置 false则直接获取本地配置
disconf.enable.remote.conf=true #
# 配置服务器的 HOST,用逗号分隔 127.0.0.1:8004,127.0.0.1:8004
#
disconf.conf_server_host=172.20.50.26:8990
#disconf.conf_server_host=127.0.0.1:80 # 版本, 请采用 X_X_X_X 格式
disconf.version=1_0_0_0 # APP 请采用 产品线_服务名 格式
disconf.app=pinganwj_appt # 环境disco
disconf.env=dev # 忽略哪些分布式配置,用逗号分隔
disconf.ignore= # 获取远程配置 重试次数,默认是3次
disconf.conf_server_url_retry_times=1
# 获取远程配置 重试时休眠时间,默认是5秒
disconf.conf_server_url_retry_sleep_seconds=1 # 用户指定的下载文件夹, 远程文件下载后会放在这里
disconf.user_define_download_dir=./disconf/download # 下载的文件会被迁移到classpath根路径下,强烈建议将此选项置为 true(默认是true)
disconf.enable_local_download_dir_in_class_path=true

3、通过xml的分布式配置

添加静态配置文件

<!-- 使用托管方式的disconf配置(无代码侵入, 配置更改不会自动reload) -->
<bean id="configproperties_no_reloadable_disconf"
class="com.baidu.disconf.client.addons.properties.ReloadablePropertiesFactoryBean">
<property name="locations">
<list>
<value>file:config/global.properties</value>
<value>file:config/jdbc.properties</value>
<value>file:config/config-db.properties</value>
<value>file:config/clinic-api.properties</value>
</list>
</property>
</bean>
<bean id="propertyConfigurerForProject1" class="com.abcde.core.base.utils.PropertyPlaceholder">
<property name="ignoreResourceNotFound" value="true" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="propertiesArray">
<list>
<ref bean="configproperties_no_reloadable_disconf" />
</list>
</property>
</bean>

添加动态配置(托管式),启动时下载配置文件;配置文件变化时,负责动态推送。程序不会自动reload配置,需要自己写回调函数(实现IDisconfUpdate接口,并添加DisconfUpdateService注解)。

<!-- 使用托管方式的disconf配置(无代码侵入, 配置更改会自动reload) -->
<bean id="configproperties_reloadable_disconf"
class="com.baidu.disconf.client.addons.properties.ReloadablePropertiesFactoryBean">
<property name="locations">
<list>
<value>file:config/kafka.properties</value>
<value>file:config/emailSendConfig.properties</value>
</list>
</property>
</bean> <bean id="propertyConfigurerForProject"
class="com.baidu.disconf.client.addons.properties.ReloadingPropertyPlaceholderConfigurer">
<property name="ignoreResourceNotFound" value="true" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="propertiesArray">
<list>
<ref bean="configproperties_reloadable_disconf" />
</list>
</property>
</bean>
@Component
@DisconfUpdateService(confFileKeys = { "kafaka.properties" })
public class KafakaConfigCallback implements IDisconfUpdate { @Override
public void reload() throws Exception {
} }

4、基于注解的分布式配置

@Configuration
@DisconfFile(filename="redis.properties")
public class JedisConfig implements IDisconfUpdate { protected static final Logger LOGGER = LoggerFactory
.getLogger(JedisConfig.class); // 代表连接地址
private String host; // 代表连接port
private int port; /**
* 地址, 分布式文件配置
*
* @return
*/
@DisconfFileItem(name = "redis.host", associateField = "host")
public String getHost() { return host;
} public void setHost(String host) { this.host = host;
} /**
* 端口, 分布式文件配置
*
* @return
*/
@DisconfFileItem(name = "redis.port", associateField = "port")
public int getPort() { return port;
} public void setPort(int port) { this.port = port;
} public void reload() throws Exception { LOGGER.info("host: " + host);
}
}

disconf分布式配置管理(二) 与spring集成的更多相关文章

  1. Disconf 分布式配置管理平台(安装配置)

    Disconf 分布式配置管理平台(安装配置) 依赖环境 Nginx:处理静态资源请求.动态请求转发到Tomcat Tomcat:处理Nginx的请求 Redis:用户session管理 MySQL: ...

  2. Spring+SpringMVC+MyBatis+easyUI整合进阶篇(十二)Spring集成Redis缓存

    作者:13 GitHub:https://github.com/ZHENFENG13 版权声明:本文为原创文章,未经允许不得转载. 整合Redis 本来以为类似的Redis教程和整合代码应该会很多,因 ...

  3. 二)spring 集成 ehcache jgroups 集群

    依赖 <dependency> <groupId>org.springframework</groupId> <artifactId>spring-co ...

  4. 二、spring集成ibatis进行数据源事务管理拦截器环境配置

    1.dataSource-applicationContext.xml文件配置理解:(spring1.2.8+ibatis1.5.3)1.1)配置数据源 DriverManagerDataSource ...

  5. 分布式配置管理平台 - Disconf介绍

    原博客地址:http://blog.csdn.net/zhu_tianwei/article/details/47984545 Disconf专注于各种分布式系统配置管理的通用组件/通用平台,提供统一 ...

  6. RabbitMQ安装和使用(和Spring集成)

    一.安装Rabbit MQ Rabbit MQ 是建立在强大的Erlang OTP平台上,因此安装Rabbit MQ的前提是安装Erlang.通过下面两个连接下载安装3.2.3 版本: 下载并安装 E ...

  7. 分布式配置管理平台 Disconf

    Distributed Configuration Management Platform(分布式配置管理平台) 专注于各种 分布式系统配置管理 的通用组件/通用平台, 提供统一的配置管理服务. 包括 ...

  8. Disconf —— 来自百度的分布式配置管理平台

    摘要 为了更好的解决分布式环境下多台服务实例的配置统一管理问题,本文提出了一套完整的分布式配置管理解决方案(简称为disconf[4],下同).首先,实现了同构系统的配置发布统一化,提供了配置服务se ...

  9. 百度分布式配置管理平台-Disconf

    Disconf介绍 全称:Distributed Configuration Management Platform,即分布式配置管理平台. Disconf专注于各种分布式系统配置管理的通用组件和通用 ...

  10. 从零开始学 Java - Spring 集成 Memcached 缓存配置(二)

    Memcached 客户端选择 上一篇文章 从零开始学 Java - Spring 集成 Memcached 缓存配置(一)中我们讲到这篇要谈客户端的选择,在 Java 中一般常用的有三个: Memc ...

随机推荐

  1. 数据标注工具 doccano

    目录 安装 运行 doccano 使用 doccanno 上传数据 定义标签 添加成员 开始标注 导出数据 查看数据 统计 数据标注工具 Label-Studio 安装 打开命令行(cmd.termi ...

  2. LED虚拟拍摄-跟踪算法

    LED虚拟拍摄-跟踪算法 图引用拍摄黑科技,LED虚拟影棚揭秘 标定流程 上面是一台Track设备,现精度比较高的主要是Redspy,Mosys,一般影视用这二种,其底层技术参考SMAL单目+惯性传感 ...

  3. Nuxt3 的生命周期和钩子函数(四)

    title: Nuxt3 的生命周期和钩子函数(四) date: 2024/6/28 updated: 2024/6/28 author: cmdragon excerpt: 概述了Nuxt3的六个关 ...

  4. C++ 史上首次超越 C,Python 第二!

    TIOBE 公布了 2024 年 6 月的编程语言排行榜--C++ 史上首次超越 C,跃至榜二,仅次于 Python. C++ 是一种广泛应用于嵌入式系统.游戏开发和金融交易软件等领域的语言,在本月成 ...

  5. Xilinx XCZU7EV评估板规格书(四核ARM Cortex-A53 + 双核ARM Cortex-R5 + FPGA,主频1.5GHz)

    1 评估板简介 创龙科技TLZU-EVM是一款基于Xilinx UltraScale+ MPSoC系列XCZU7EV高性能处理器设计的高端异构多核SoC评估板,处理器集成PS端(四核ARM Corte ...

  6. NXP i.MX 6ULL工业核心板规格书( ARM Cortex-A7,主频792MHz)

    1 核心板简介 创龙科技SOM-TLIMX6U是一款基于NXP i.MX 6ULL的ARM Cortex-A7高性能低功耗处理器设计的低成本工业级核心板,主频792MHz,通过邮票孔连接方式引出Eth ...

  7. Sql Server 创建用户并限制权限

    创建登录名 使用sa或者Windows身份验证登录,[安全性]-[登录名],右键[新建登录名] 设置登录名属性 设置数据库权限 db owner --拥有数据库全部权限,包括删除数据库权限 db ac ...

  8. 用StabilityMatrix一键安装Stable Diffusion

    Stable Diffusion是2022年发布的深度学习文字到图像生成模型,它既能免费使用,又能部署在本地端,又有非常多的模型可以直接套用,在使用体验上比Midjourney和DALL-E更加强大. ...

  9. 小程序-云数据库的add,get,remove,update

    云数据库的使用就是使用简单的原生封装wx.cloud.database().collection("list"),然后就是add,get,remove,update四个方法 初始化 ...

  10. PowerBuilder现代编程方法X11:PB程序完全跨平台方案

    PB可能要支持Windows.macOS.Linux.iOS.Android与鸿蒙操作系统和X86.ARM.RISC-V与国产龙芯CPU的原生应用了! PowerBuilder现代编程方法X11:PB ...