java - disconf分布式管理-配置文件篇
2016-11-29 11:08
387 查看
1、pom.xml文件引入disconf依赖jar包 <dependencies> <dependency> <groupId>com.baidu.disconf</groupId> <artifactId>disconf-client</artifactId> <version>2.6.35</version> </dependency> <dependency> <groupId>com.baidu.disconf</groupId> <artifactId>disconf-core</artifactId> <version>2.6.35</version> </dependency> </dependencies> 2、applicationContext.xml文件引入disconf配置 <!-- 使用disconf必须添加以下配置 --> <bean id="disconfMgrBean" class="com.baidu.disconf.client.DisconfMgrBean" destroy-method="destroy"> <property name="scanPackage" value="com.source"/> </bean> <bean id="disconfMgrBean2" class="com.baidu.disconf.client.DisconfMgrBeanSecond" init-method="init" destroy-method="destroy"> </bean> <!--disconf 托管文件 配置更改会自动reload--> <bean id="configproperties_disconf" class="com.baidu.disconf.client.addons.properties.ReloadablePropertiesFactoryBean"> <property name="locations"> <list> <value>classpath:/logback.xml</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_disconf"/> </list> </property> </bean> 3、resources目录下新建disconf.properties环境配置文件 #是否使用远程配置文件,true(默认)从远程获取配置信息,false从本地获取配置文件 disconf.enable.remote.conf=true #disconf配置服务器的HOST,用逗号分隔127.0.0.1:8000,127.0.0.1:8000 disconf.conf_server_host=127.0.0.1:8000 #版本 disconf.version=1.0.0 #产品线_服务名 disconf.app=source #环境 disconf.env=test #debug debug=true #忽略哪些分布式配置,用逗号分隔 disconf.ignore= #获取远程配置 重试次数,默认是3次 disconf.conf_server_url_retry_times=1 #获取远程配置 重试时休眠时间,默认是5秒 disconf.conf_server_url_retry_sleep_seconds=1 #指定文件下载路径 #disconf.user_define_download_dir=F:\space\CarSource\target\classes # 配置文件下载默认classpath,false为下载到指定路径 disconf.enable_local_download_dir_in_class_path=true
Disconf接入,各环境部署使用同一个war包,需要修改tomcat的服务端的配置。
tomcat bin目录下的catalina.sh
找到:# Bugzilla 37848: only output this if we have a TTY
在上面增加:
JAVA_OPTS="$JAVA_OPTS -Ddisconf.env=test-Ddisconf.enable.remote.conf=true -Ddisconf.conf_server_host=127.0.0.1:8000"
根据指定的disconf环境进行部署,此时,diconf.properties文件中的以上被指定了的变量将会被写入指定值,进而读取该环境下其他托管的配置文件信息。
4、获取.properties文件的内容
DisconfDataGetter.getByFile("source.properties").get("test.value").toString();
test.value为source.properties文件中的要获取的value对应的key.
5、spring+mybatis的配置文件(spring-mybatis.xml)中,去除beans属性中的
default-autowire="byName"
具体原因可参见:https://my.oschina.NET/u/1455908/blog/215953
Disconf接入,各环境部署使用同一个war包,需要修改tomcat的服务端的配置。
tomcat bin目录下的catalina.sh
找到:# Bugzilla 37848: only output this if we have a TTY
在上面增加:
JAVA_OPTS="$JAVA_OPTS -Ddisconf.env=test-Ddisconf.enable.remote.conf=true -Ddisconf.conf_server_host=127.0.0.1:8000"
根据指定的disconf环境进行部署,此时,diconf.properties文件中的以上被指定了的变量将会被写入指定值,进而读取该环境下其他托管的配置文件信息。
4、获取.properties文件的内容
DisconfDataGetter.getByFile("source.properties").get("test.value").toString();
test.value为source.properties文件中的要获取的value对应的key.
5、spring+mybatis的配置文件(spring-mybatis.xml)中,去除beans属性中的
default-autowire="byName"
具体原因可参见:https://my.oschina.NET/u/1455908/blog/215953
相关文章推荐
- java - disconf分布式管理-配置文件篇
- java - disconf分布式管理-配置文件篇
- disconf实践(二)基于XML的分布式配置文件管理,不会自动reload
- disconf实践(四)基于注解的分布式配置文件管理,自动reload
- disconf实践(三)基于XML的分布式配置文件管理,自动reload
- 分布式配置文件管理工具disconf部署以及运用
- java 高新技术【6】 反射开发框架以及用 类加载器 管理资源和配置文件
- 简单的ant配置文件用来管理java程序
- Disconf —— 来自百度的分布式配置管理平台
- java 高新技术【6】 反射开发框架以及用 类加载器 管理资源和配置文件
- 分布式配置管理平台 Disconf
- 分布式配置管理平台Disconf
- 分布式配置管理平台Disconf
- 分布式配置管理平台Disconf
- Disconf,百度的分布式配置管理平台
- Agile PLM: 用IIS给分布式文件管理DFM配置HTTP Proxy
- 彻底摆脱配置文件,zkconfigutil分布式环境中配置项管理工具(持续更新中)
- 分布式配置管理平台-disconf部署
- 分布式配置管理平台Disconf
- Linux Centos7下Disconf分布式系统配置管理安装