java - disconf分布式管理-配置文件篇
来源:互联网 发布:网络教育 高起专 时间 编辑:程序博客网 时间:2024/04/26 15:42
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分布式管理-配置文件篇
- java - disconf分布式管理-配置文件篇
- 分布式配置文件管理工具disconf部署以及运用
- 分布式配置管理平台 - Disconf web管理端安装
- 分布式配置管理平台 - Disconf web管理端安装
- 分布式配置管理平台 - Disconf web管理端安装【转】
- Linux Centos7下Disconf分布式系统配置管理安装
- 分布式配置管理平台-Disconf
- 分布式配置管理平台 Disconf
- disconf 分布式配置
- 分布式配置管理平台 Disconf
- 分布式配置管理平台Disconf
- 分布式配置管理平台Disconf
- 分布式配置管理平台Disconf
- 百度配置管理disconf配置文件
- 分布式配置管理平台 - Disconf介绍
- disconf-注解式分布式配置
- LeetCode 201. Bitwise AND of Numbers Range
- linux-文件权限
- Spark笔记:RDD基本操作(上)
- Nginx反向代理实现会话(session)保持的两种方式
- 推断性统计部分(三)---假设检验
- java - disconf分布式管理-配置文件篇
- Access denied for user(这个几乎让我怀疑人生的异常)
- 让MySql支持Emoji表情(MySQL中4字节utf8字符保存方法)
- android权限(permission)大全
- 第1章 BashShell命令------------(变量数组、alias)
- 数学(Anton and School,cf 734F)
- 成长经验----ABS出差
- 自定义的基本的dialog
- 几个常用的报表服务器性能优化方法