上一章介绍了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. Sealos 5.0 正式发布,云本应该是操作系统

    把所有资源抽象成一个整体,一切皆应用,这才是云应该有的样子. 2018 年 8 月 15 日 Sealos 提交了第一行代码. 随后开源社区以每年翻倍的速度高速增长. 2022 年我们正式创业,经历一 ...

  2. nginx 反向代理(proxy)与负载均衡(upstream)应用实践

    集群介绍 集群就是指一组(若干个)相互独立的计算机,利用高速通信网络组成的一个较大的计算机服务系统,每个集群节点(即集群中的每台计算机)都是运行各自服务的独立服务器.这些服务器之间可以彼此通信,协同向 ...

  3. C#多态性学习,虚方法、抽象方法、接口等用法举例

    1. 多态性定义   C#中的多态性是OOP(面向对象编程)的一个基本概念,它允许一个对象在不同情况下表现出不同的行为,以增强代码的可重用性和灵活性.   根据网上的教程,我们得知C#多态性分为两类, ...

  4. .NET6 API 部署标准流程

    一.安装dotnet环境 #第一步:将 Microsoft 包签名密钥添加到受信任密钥列表,并添加 Microsoft 包存储库 sudo rpm -Uvh https://packages.micr ...

  5. 解决方案 | win10任务栏假死,桌面鼠标可以动但是无法点击任务栏图标

    1 背景 今天电脑不知道什么原因,鼠标出现了无法点击任务栏图标的情况,但是桌面上可以晃动. 2 解决过程 (方法1-3对我无效,但是不代表对你们无效,) 方法1:重启资源管理器. 方法2:电脑重启.或 ...

  6. Spring MVC 中的拦截器的使用“拦截器基本配置” 和 “拦截器高级配置”

    1. Spring MVC 中的拦截器的使用"拦截器基本配置" 和 "拦截器高级配置" @ 目录 1. Spring MVC 中的拦截器的使用"拦截器 ...

  7. 精品 IDEA 插件大汇总!值得收藏

    轻松提高 Java 开发效率 俗话说,工欲善其事,必先利其器.想要提升编程开发效率,必须选择一款顺手的开发工具. 对于 Java 开发者,JetBrains IDEA 无疑是目前最主流的开发工具,既简 ...

  8. MySQL ibdata1文件太大的解决办法

    在MySQL数据库中,如果不指定innodb_file_per_table=1参数单独保存每个表的数据,MySQL的数据都会存放在ibdata1文件里,时间久了这个文件就会变的非常大. 下面是参考网上 ...

  9. System.NotSupportedException:“无法显式设置 SplitterPanel 的高度。改在 SplitContainer 上设置 SplitterDistance。”

    System.NotSupportedException:"无法显式设置 SplitterPanel 的高度.改在 SplitContainer 上设置 SplitterDistance.& ...

  10. [oeasy]python0072_自定义小动物变色_cowsay_color_boxes_asciiart

    修改颜色 回忆上次内容 上次搞的是 颜色 前景颜色 总共有 7 种基本色 还有什么 好玩的 么? 可以 给小动物 上色 吗? 配合 先将cowsay结果 输出重定向 sudo apt install ...