原文链接:http://blog.csdn.net/jthink_/article/details/50556740
- disconf-web配置
- 在disconf-web上点击新建app创建一个新的app,这里假设app名字为:app_test
- 在disconf-web上点击新建配置文件新建一个配置文件,APP选择刚刚的app_test,版本自定义成:0.0.1,环境可选择local环境,直接选择上传文件,比如我们这里上传dev.properties,内容如下:
disconf.test=disconf_test
- 项目使用
- pom.xml中加入disconf,如下:
<dependency>
由于自己项目需要下载disconf托管的配置文件,所以项目还需要引入httpclient
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.7.2</version>
</dependency><dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.1</version>
</dependency> - 准备disconf.properties
# 是否使用远程配置文件
该配置文件需要放在resources根目录下(这点感觉是很奇怪的规定,其实应该可以指定放入到resource目录下的任何位置)
# true(默认)会从远程获取配置 false则直接获取本地配置
enable.remote.conf=true
#
# 配置服务器的 HOST,用逗号分隔 127.0.0.1:8000,127.0.0.1:8000
#
conf_server_host=127.0.0.1:8991
# 版本, 请采用 X_X_X_X 格式
version=0.0.1
# APP 请采用 产品线_服务名 格式
app=app_test
# 环境
env=local
# debug
debug=true
# 忽略哪些分布式配置,用逗号分隔
ignore=
# 获取远程配置 重试次数,默认是3次
conf_server_url_retry_times=1
# 获取远程配置 重试时休眠时间,默认是5秒
conf_server_url_retry_sleep_seconds=1 - 修改applicationContext.xml
在applicationContext.xml中加入如下配置:- 包扫描
<context:component-scan base-package="xxx.xxx.xxx" />
<aop:aspectj-autoproxy proxy-target-class="true" /> -
bean配置
<bean id="disconfMgrBean" class="com.baidu.disconf.client.DisconfMgrBean"
destroy-method="destroy">
<property name="scanPackage" value="upsmart.trans.test"/>
</bean>
<bean id="disconfMgrBean2" class="com.baidu.disconf.client.DisconfMgrBeanSecond"
init-method="init" destroy-method="destroy">
</bean>
- 包扫描
- 使用示例
java代码如下:
@Service
@DisconfFile(filename = "dev.properties")
public class QueryService {private String disconfTest;@DisconfFileItem(name = "disconf.test", associateField = "disconfTest")
public String getDisconfTest() {
return disconfTest;
}public void setDisconfTest(String disconfTest) {
this.disconfTest = disconfTest;
}这样disconfTest会随着disconf-web中对dev.properties值的修改而修改
- pom.xml中加入disconf,如下:
- 总结
该方法对代码的侵入性太强,不太适合对老项目的变更
参考:https://github.com/knightliao/disconf/wiki
相关推荐
在使用 Disconf 时,我们可以使用注解式的分布式配置文件,以便更方便地使用 Disconf 的功能。 Disconf 是一个功能强大且易用的分布式配置管理系统,可以帮助开发者更方便地管理和维护项目中的配置文件。
二十五、商城 - 运营商后台审核上下架-注解式事务配置(13)11.youlexuan.zip
Spring MVC学习(六)-------注解式控制器详解1
NULL 博文链接:https://wenkaixuan.iteye.com/blog/906290
Spring+SpringMVC+MyBatis整合相关配置文件:注解+xml配置。个别处需要根据使用情况修改,映射配置文件为示例,需自行编写。依赖maven管理
4.3、强兼容性:为程序添加了分布式配置注解后,开启Disconf则使用分布式配置;若关闭Disconf则使用本地配置;若开启Disconf后disconf-web不能正常Work,则Disconf使用本地配置。 5、支持配置项多个项目共享,支持...
JAVA设计模式--程序设计--反射--注解--泛型
---注解---.xmind Java常用各种注解
Eclipse-SpringBoot框架-注解介绍.docxEclipse-SpringBoot框架-注解介绍.docx
spring-demo10-注解-IOC.zip
Spring系列--注解.md
该案例使用SpringBoot整合了MyBatis,支持2种配置,注解版和xml配置。
spring-demo13-注解-@Value.zip
本资源是一个S2SH架构整合的一个完整例子,包含:struts2的完整配置及实例,使用c3p0连接池,Spring的事务管理、类路径扫描管理功能、注解功能。例子本人已测试通过,所有配置和代码都有完整的注释,适合初学者或者...
20171010 : 新增输入监听,对@Money/@MaxLength/@Password1/@Password2 注解进行修改。使用方式不变。 当在 控件初始化后 调用Validate.reg(this)方法,会自动给控件添加输入规则/监听事件。详细说明可以看...
Struts2-注解第一个例子
详细的反射-动态代理-注解
- **分布式配置管理**:支持分布式系统中的外部化配置,配置更改时自动刷新。 - **消息驱动能力**:基于 Spring Cloud Stream 为微服务应用构建消息驱动能力。 - **分布式事务**:使用 @GlobalTransactional 注解...
方剂学-第二版-李冀-方歌-注解.doc
springmvc注解配置。springmvc注解配置。springmvc注解配置。springmvc注解配置。