上一篇介绍了基于xml的非自动reload的分布式配置文件管理,这一篇介绍自动reload的方式(基于disconf实践二)。

1. 修改RedisConfig.java

 package org.springinaction.weather.config;

 public class RedisConfig {

     private String host;

     private String port;

     public String getHost() {
return host;
} public String getPort() {
return port;
} public void setHost(String host) {
this.host = host;
} public void setPort(String port) {
this.port = port;
} }

2. 新增回调

 package org.springinaction.weather.config.callback;

 import org.springframework.stereotype.Component;

 import com.baidu.disconf.client.common.annotations.DisconfUpdateService;
import com.baidu.disconf.client.common.update.IDisconfUpdate; @Component
@DisconfUpdateService(confFileKeys = { "redis.properties" })
public class RedisConfigCallback implements IDisconfUpdate { @Override
public void reload() throws Exception {
} }

3. 修改spring配置文件

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd"> <!-- 使用disconf必须添加以下配置 -->
<bean id="disconfMgrBean" class="com.baidu.disconf.client.DisconfMgrBean"
destroy-method="destroy">
<property name="scanPackage" value="org.springinaction.weather.config" />
</bean>
<bean id="disconfMgrBean2" class="com.baidu.disconf.client.DisconfMgrBeanSecond"
init-method="init" destroy-method="destroy">
</bean> <!-- 使用托管方式的disconf配置(无代码侵入, 配置更改会自动reload) -->
<bean id="configproperties_reloadable_disconf"
class="com.baidu.disconf.client.addons.properties.ReloadablePropertiesFactoryBean">
<property name="locations">
<list>
<value>redis.properties</value>
</list>
</property>
</bean> <bean id="propertyConfigurer"
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> <bean id="redisConfig" class="org.springinaction.weather.config.RedisConfig">
<property name="host" value="${redis.host}" />
<property name="port" value="${redis.port}" />
</bean>
</beans>

修改之后,在管理端修改redis.properties的配置信息时,应用会自动reload并修改相应的参数。

disconf实践(三)基于XML的分布式配置文件管理,自动reload的更多相关文章

  1. disconf实践(二)基于XML的分布式配置文件管理,不会自动reload

    上一篇博文介绍了disconf web的搭建流程,这一篇就介绍disconf client通过配置xml文件来获取disconf管理端的配置信息. 1. 登录管理端,并新建APP,然后上传配置文件 2 ...

  2. disconf实践(四)基于注解的分布式配置文件管理,自动reload

    上一篇讲解了基于xml的自动reload的分布式配置文件管理,这一篇讲解基于注解的自动reload的方式(基于disconf实践二). 1. 修改spring配置文件 <?xml version ...

  3. Spring 框架的概述以及Spring中基于XML的IOC配置

    Spring 框架的概述以及Spring中基于XML的IOC配置 一.简介 Spring的两大核心:IOC(DI)与AOP,IOC是反转控制,DI依赖注入 特点:轻量级.依赖注入.面向切面编程.容器. ...

  4. 基于XML的AOP配置

    创建spring的配置文件并导入约束 此处要导入aop的约束 <?xml version="1.0" encoding="UTF-8"?> < ...

  5. 基于zookeeper实现分布式配置中心(二)

    上一篇(基于zookeeper实现分布式配置中心(一))讲述了zookeeper相关概念和工作原理.接下来根据zookeeper的特性,简单实现一个分布式配置中心. 配置中心的优势 1.各环境配置集中 ...

  6. 01Spring基于xml的IOC配置--入门

    01Spring基于xml的IOC配置 1.创建一个普通的maven工程 1.1 选择maven,不用骨架,点击下一步. 1.2 填写GroupId.ArtifactId.Version.填完点击下一 ...

  7. Spring中AOP的基于xml开发和配置

    pom文件: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http ...

  8. 基于zookeeper实现分布式配置中心(一)

    最近在学习zookeeper,发现zk真的是一个优秀的中间件.在分布式环境下,可以高效解决数据管理问题.在学习的过程中,要深入zk的工作原理,并根据其特性做一些简单的分布式环境下数据管理工具.本文首先 ...

  9. mybatis学习一:基于xml与注解配置入门实例与问题

    注:本case参考自:http://www.cnblogs.com/ysocean/p/7277545.html 一:Mybatis的介绍: MyBatis 本是apache的一个开源项目iBatis ...

随机推荐

  1. Microsoft ReportViewer 控件类型版本兼容问题及解决方法

    错误 Parser Error Message: The base class includes the field 'rvEquipment', but its type (Microsoft.Re ...

  2. C#解析PDF

    C#解析PDF的方式有很多,比较好用的有ITestSharp和PdfBox. PDF内容页如果是图片类型,例如扫描件,则需要进行OCR(光学字符识别). 文本内容的PDF文档,解析的过程中,我目前仅发 ...

  3. 关于iFrame特性总计和iFrame跨域解决办法

    1.iframe 定义和用法 iframe 元素会创建包含另外一个文档的内联框架(即行内框架). HTML 与 XHTML 之间的差异 在 HTML 4.1 Strict DTD 和 XHTML 1. ...

  4. IE、火狐、谷歌浏览器下兼容统一select样式

    项目开发时,对于不同浏览器下的select样式不统一问题,各种查,这里记录一下,项目已使用 IE浏览器下样式: 火狐浏览器下样式: 谷歌浏览器下样式: 上代码: 1.html 2.css 至此,大功告 ...

  5. SP从32位系统到64位系统的迁移方法

    前提:目标系统为64位1.在32位系统下正常安装SP,获取SP运行时必须的文件2.将[浪潮集团金融事业部]目录拷贝到目标系统的[C:\Program Files]目录3.进入目标系统的[浪潮集团金融事 ...

  6. 计算fibonacci数(多种方法)

    #include <iostream> using namespace std; //计算fibonacci数 //方法一:二分递归法,时间复杂度为O(2^n),额外空间复杂度为常数 in ...

  7. flask代码统计作业

    用户表: create table userInfo( id int not null unique auto_increment, name )not null, password ) not nu ...

  8. PHP中的trait方法冲突

    laravel使用中我们可能需要对User model使用softdelete这个功能,以便删除后还可以恢复,不幸的是entrust模块也有这个方法,两者产生冲突, 解决办法: https://lar ...

  9. nginx部署及简单优化

    研究nginx优化时反复安装清理nginx,为方便做了一个简单部署脚本,用的最新稳定版1.14.0,默认路径,加入systemd系统进程管理中,可以通过systemd管理nginx的启动.终止.重载. ...

  10. C# winfrom界面跳转闪烁问题解决方法

    在窗体的构造函数中添加代码: SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.AllPaintingInWmPaint, ...