disconf分布式配置管理(二) 与spring集成
上一章介绍了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集成的更多相关文章
- Disconf 分布式配置管理平台(安装配置)
Disconf 分布式配置管理平台(安装配置) 依赖环境 Nginx:处理静态资源请求.动态请求转发到Tomcat Tomcat:处理Nginx的请求 Redis:用户session管理 MySQL: ...
- Spring+SpringMVC+MyBatis+easyUI整合进阶篇(十二)Spring集成Redis缓存
作者:13 GitHub:https://github.com/ZHENFENG13 版权声明:本文为原创文章,未经允许不得转载. 整合Redis 本来以为类似的Redis教程和整合代码应该会很多,因 ...
- 二)spring 集成 ehcache jgroups 集群
依赖 <dependency> <groupId>org.springframework</groupId> <artifactId>spring-co ...
- 二、spring集成ibatis进行数据源事务管理拦截器环境配置
1.dataSource-applicationContext.xml文件配置理解:(spring1.2.8+ibatis1.5.3)1.1)配置数据源 DriverManagerDataSource ...
- 分布式配置管理平台 - Disconf介绍
原博客地址:http://blog.csdn.net/zhu_tianwei/article/details/47984545 Disconf专注于各种分布式系统配置管理的通用组件/通用平台,提供统一 ...
- RabbitMQ安装和使用(和Spring集成)
一.安装Rabbit MQ Rabbit MQ 是建立在强大的Erlang OTP平台上,因此安装Rabbit MQ的前提是安装Erlang.通过下面两个连接下载安装3.2.3 版本: 下载并安装 E ...
- 分布式配置管理平台 Disconf
Distributed Configuration Management Platform(分布式配置管理平台) 专注于各种 分布式系统配置管理 的通用组件/通用平台, 提供统一的配置管理服务. 包括 ...
- Disconf —— 来自百度的分布式配置管理平台
摘要 为了更好的解决分布式环境下多台服务实例的配置统一管理问题,本文提出了一套完整的分布式配置管理解决方案(简称为disconf[4],下同).首先,实现了同构系统的配置发布统一化,提供了配置服务se ...
- 百度分布式配置管理平台-Disconf
Disconf介绍 全称:Distributed Configuration Management Platform,即分布式配置管理平台. Disconf专注于各种分布式系统配置管理的通用组件和通用 ...
- 从零开始学 Java - Spring 集成 Memcached 缓存配置(二)
Memcached 客户端选择 上一篇文章 从零开始学 Java - Spring 集成 Memcached 缓存配置(一)中我们讲到这篇要谈客户端的选择,在 Java 中一般常用的有三个: Memc ...
随机推荐
- MYSQL8存储过程生成日历表以及异常处理
一.环境 数据库:mysql8.0.25 社区版 操作系统:windows 11 ------------------------------------ 二.创建日历表 CREATE TABLE ` ...
- git连接到https服务器时出现“gnutls_handshake() failed”
git连接到https服务器时出现"错误: gnutls_handshake()失败" 问题描述 当我尝试使用git连接到任何HTTPS服务器时(例如git clone),它会出现 ...
- SQL注入攻击及防御
SQL注入攻击及防御 1.项目实验环境 目标靶机OWASP_Broken_Web_App_VM_1.2: https://sourceforge.net/projects/owaspbwa/files ...
- OpenCV程序练习(三):图像运算
一.图像加法运算 代码 import cv2 img=cv2.imread("demoimg.jpg",0) #读取图片,参数0等价于cv2.IMREAD_GRAYSCALE,将图 ...
- 案例分享!RK3568 + FPGA多通道AD采集处理与显示
案例展示 测试数据汇总 表 1 本文带来的是基于瑞芯微RK3568J + 紫光同创Logos-2的ARM + FPGA多通道AD采集处理与显示案例. 本次案例演示的开发环境如下: Wind ...
- 一次Java服务内存过高的分析过程
现象 年前,收到了短信报警,显示A服务的某台机器内存过高,超过80% 如上图所示,内存会阶段性增加.奇怪的是,十多台机器中只有这一台有这个问题 堆内内存分析 最先怀疑是内存泄漏的问题,所以首先使用jm ...
- npm install及其目录结构
npm install 安装包及其依赖.npm install: 默认情况下,安装package.json文件中列出的所有依赖.加-P或--production后,只安装dependencies列出的 ...
- JS 延迟加载
function sleep(numberMillis) { var now = new Date(); var exitTime = now.getTime() + numberMillis; wh ...
- Dubbo依赖
项目依赖 Dubbo依赖 <!--Dubbo依赖--> <dependency> <groupId>com.alibaba</groupId> < ...
- 使用bootstrap-select 动态加载数据不显示的问题,级联数据置为空
动态加载数据 $.showLoading('数据加载中');//开启遮挡层 $.ajax({ url: "/PickoutStock/GetSendReceive", data: ...