kl个人博客 首页>>分布式,架构>>Disconf服务Client的使用

Disconf服务Client的使用

ps:因为后来编辑过一次,由于编辑器的原因,丢失了一大部分数据,所以下面很乱啊有木有,不过没关系,我已将difconf的服务配置以及使用的实例上上传到coding了,大家下载下来可以直接用(包括difconf,redis,zookeeper-3.3.6,nginx-1.9.12,apache-tomcat-7.0.68)等环境以及使用的demo

地址:https://coding.net/u/kailingchen/p/disconfDemo/git



说明

disconf服务是基于spring开发的,这里假定你的项目使用了spring框架,并使用maven构建


准备

在你的项目pom.xml文件中加入如下依赖


配置

1.首先需要配置disconfClient的bean,主要是配置spring的注解扫描路径,最后别忘了加载你的bean配置文件


2.配置disconf.properties

# 是否使用远程配置文件
# true(默认)会从远程获取配置 false则直接获取本地配置
disconf.enable.remote.conf=true
# 配置服务器的 HOST,用逗号分隔  127.0.0.1:8000,这个是必填项,其他都是选填
disconf.conf_server_host=localhost:8081
# 版本, 请采用 X_X_X_X 格式
disconf.version=1_0_0_0
# APP 请采用 产品线_服务名 格式
disconf.app=disconf_demo
# 环境
disconf.env=rd
# debug
#debug=true
# 忽略哪些分布式配置,用逗号分隔
ignore=
# 获取远程配置 重试次数,默认是3次
disconf.conf_server_url_retry_times=1
# 获取远程配置 重试时休眠时间,默认是5秒
disconf.conf_server_url_retry_sleep_seconds=1
disconf.user_define_download_dir=./
3.配置你的config

@Service
@Scope("singleton")
@DisconfFile(filename = "myTestConifg.properties")//这个是你远程服务器的文件名
public  class MyConfig {

private static String imageCdn;
@DisconfFileItem(name="IMAGECDN")//这个name就是你配置的key值
public static String getImageCdn() {
return imageCdn;
}

public static void setImageCdn(String imageCdn) {
MyConfig.imageCdn = imageCdn;
}
}

使用
    @Autowired

    private  MyConfig myConfig;



kl个人博客