概念
专注于各种「分布式系统配置管理」的「通用组件」和「通用平台」, 提供统一的「配置管理服务」。
使用流程
第一步:去disconf服务器上上传自己项目的配置文件。
- 添加app,app名称对应自己的项目。
- 添加配置文件,版本自定义例如 0_0_2,然后选择输入方式,key值填youFile.properties下面的值填写自己所需要的配置(注:key:youFile.properties必须配置),配置的app名称和版本需和disconf配置文件中一致。
第二步:如何使用spring配置disconf,如下步骤所示:
I、添加maven依赖:
<dependency>
<groupId>com.nbugs.disconf.start</groupId>
<artifactId>disconf</artifactId>
<version>1.2.5</version>
</dependency>
II、添加disconf配置和disconf.properties在根目录下(resource目录下)
disconf.enable.remote.conf=true
disconf.conf_server_host=10.127.12.114
disconf.version=0_0_2
disconf.app=order_service
disconf.env=qa
disconf.ignore=
disconf.conf_server_url_retry_sleep_seconds=1
disconf.user_define_download_dir=./src/main/resources/config
disconf.common_app_conf_files_name=common.properties,datasource-user.properties,datasource-order.properties,mq.properties,redis-core.properties
disconf.app_conf_files_name=
III、修好/添加AppContext扫描文件路径
package myDisconf;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
@Configuration
@ImportResource(locations = { "classpath:spring/*", "classpath*:spring/disconf.xml" })
public class AppContext {
}
Disconf配置详解 所有的配置均可以通过命令行 -Dname=value参数传入。
配置 | 说明 | 默认值 | 是否必填 |
---|---|---|---|
disconf.conf_server_host | 配置服务器的HOST,用逗号分隔,示例:127.0.0.1:9000,127.0.0.1:9001 | 是 | |
disconf.app | app名称 | 优先读取命令行参数,然后再读取此文件的值 | 否 |
disconf.version | 版本号 | 默认DEFAULT_VERSION。优先读取命令行参数,然后再读取此文件的值,最后才读取默认值。 | 否 |
disconf.enable.remote.conf | 是否使用远程配置文件,默认(true)会从远程获取配置,false则直接获取本地配置 | false | 否 |
disconf.env | 环境 | 默认为DEFAULT_ENV.优先读取命令行参数,然后再读取此文件的值,最后才读取默认值。 | 否 |
disconf.ignore | 忽略的分布式配置,用空格分隔 | 空 | 否 |
disconf.debug |
调试模式。调试模式下,ZK超时或断开连接后不会重新连接(常用于client单步debug)。非调试模式下,ZK超时或断开连接会自动重新连接。 | false | 否 |
disconf.conf_server_url_retry_times | 获取远程配置 重试时休眠时间,默认是3次 | 3 | 否 |
disconf.conf_server_url_sleep_seconds | 获取远程配置 重试次数,默认是5秒 | 5 | 否 |
disconf.user_define_download_dir |
用户定义的下载文件夹, 远程文件下载后会放在这里。注意,此文件夹必须有有权限,否则无法下载到这里 | ./disconf/download/ | 否 |
disconf.enable_local_download_dir_in_class_path | 下载的文件会被迁移到classpath根路径下,强烈建议将此选项置为 true(默认是true) | true | 否 |
disconf.common_app | 通用配置app名称 | common | 否 |
disconf.common_app_version | 通用配置app版本 | 默认version | 否 |
disconf.common_app_env | 通用配置环境 | 默认与app环境相同 | 否 |
disconf.app_conf_files_name | app多个配置文件加载配置;需要的配置文件中间用,号隔开;该配置下的文件只从app里面加载 | 不填写的话,只会加载对应app下的specific.properties | 否 |
disconf.common_app_conf_files_name | common app多个配置文件加载配置; | ||