{"id":18356735,"url":"https://github.com/dangdangdotcom/config-toolkit","last_synced_at":"2025-04-12T23:32:56.448Z","repository":{"id":22181908,"uuid":"25513889","full_name":"dangdangdotcom/config-toolkit","owner":"dangdangdotcom","description":"Config toolkit用于简化从本地配置文件到zookeeper的迁移","archived":false,"fork":false,"pushed_at":"2018-06-11T02:08:55.000Z","size":499,"stargazers_count":495,"open_issues_count":0,"forks_count":311,"subscribers_count":109,"default_branch":"master","last_synced_at":"2025-04-04T02:10:04.920Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dangdangdotcom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-21T09:29:23.000Z","updated_at":"2025-01-16T18:09:36.000Z","dependencies_parsed_at":"2022-08-19T22:51:14.955Z","dependency_job_id":null,"html_url":"https://github.com/dangdangdotcom/config-toolkit","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dangdangdotcom%2Fconfig-toolkit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dangdangdotcom%2Fconfig-toolkit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dangdangdotcom%2Fconfig-toolkit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dangdangdotcom%2Fconfig-toolkit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dangdangdotcom","download_url":"https://codeload.github.com/dangdangdotcom/config-toolkit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248647257,"owners_count":21139081,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T22:11:23.632Z","updated_at":"2025-04-12T23:32:56.428Z","avatar_url":"https://github.com/dangdangdotcom.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 分布配置工具包\n\nConfig Toolkit提供了一层对配置资源的抽象，配置可以从多种介质加载，工具内部提供了对zookeeper/本地文件/远程http文件的支持，并提供了SPI接口支持用户扩展自定义介质\n\n\u003chr\u003e\n\n### 社区\n* Group: https://groups.yahoo.com/group/config-toolkit\n* QQ群: 457997852\n* Config Toolkit Go语言版本：https://github.com/mbaight/config-toolkit-go\n* Zookeeper Java Shell: https://github.com/crnlmchina/zk-util\n\n### 文档\n文档: [https://github.com/dangdangdotcom/config-toolkit/wiki](https://github.com/dangdangdotcom/config-toolkit/wiki \"https://github.com/dangdangdotcom/config-toolkit/wiki\")\n\nRelease Note: [https://github.com/dangdangdotcom/config-toolkit/wiki/1.-release-notes](https://github.com/dangdangdotcom/config-toolkit/wiki/1.-release-notes \"https://github.com/dangdangdotcom/config-toolkit/wiki/1.-release-notes\")\n\n### 搭建配置界面\n\n#### 使用docker镜像运行config-face\n```\ndocker run -it -d -e \"zk=localhost:2181\" -p 8080:8080 crnlmchina/config-face:v3.3.0\n```\n\n#### 或者下载源码编译config-face\n```\ngit clone https://github.com/dangdangdotcom/config-toolkit.git\ncd config-toolkit/config-face\nmvn package\njava -jar config-face.jar --zk=localhost:2181\n```\n\n#### 创建初始权限配置\n使用命令行创建zookeeper配置根节点，根节点密码使用sha1加密，如果要使用明文密码，可以自行修改config-zk-web的鉴权部分代码\n以根路径为`/projectx/modulex`密码为`abc`为例\n```\npython -c \"import hashlib;print hashlib.sha1('abc').hexdigest();\"\n# a9993e364706816aba3e25717850c26c9cd0d89d \nzkCli.sh -server localhost:2181\ncreate /projectx 1\ncreate /projectx/modulex a9993e364706816aba3e25717850c26c9cd0d89d\n```\n#### 登录config-web，创建示例配置\n - 访问http://localhost:8080/\n - 点击\"切换根节点\"，输入/projectx/modulex，密码abc\n - 点击\"新建版本\"，输入1.0.0\n - 左侧的组管理，输入group，点击\"创建\"\n - 在右侧添加两个配置，分别为config.str=hello, config.int=7758\n\n### 项目中加载配置\n#### 添加maven依赖\n```\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.dangdang\u003c/groupId\u003e\n  \u003cartifactId\u003econfig-toolkit\u003c/artifactId\u003e\n  \u003cversion\u003e3.3.2-RELEASE\u003c/version\u003e\n\u003c/dependency\u003e\n```\n#### 使用Java代码直接获取配置\n```\nZookeeperConfigProfile configProfile = new ZookeeperConfigProfile(\"localhost:2181\", \"/projectx/modulex\", \"1.0.0\");\nGeneralConfigGroup group = new ZookeeperConfigGroup(configProfile, \"group\");\n\nString stringProperty = group.get(\"config.str\");\nPreconditions.checkState(\"hello\".equals(stringProperty));\nString intProperty = group.get(\"config.int\");\nPreconditions.checkState(7758 == Integer.parseInt(intProperty));\n```\n#### 结合spring placeholder方式注入配置\nspring xml schema\n```\n\u003cbeans xmlns=\"http://www.springframework.org/schema/beans\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n\txmlns:config=\"https://crnlmchina.github.io/config\"\n\txsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd\n             https://crnlmchina.github.io/config https://crnlmchina.github.io/config/config.xsd\"\u003e\n```\nbean配置\n```\n\u003cconfig:profile connect-str=\"localhost:2181\" root-node=\"/projectx/modulex\" \n\t\tversion=\"1.0.0\"/\u003e\n\n\u003cconfig:placeholder\u003e\n\t\u003cconfig:group node=\"property-group1\" /\u003e\t\n\t\u003cconfig:group node=\"property-group2\" /\u003e\t\n\u003c/config:placeholder\u003e\n\n\u003c!-- Your business bean --\u003e\n\u003cbean class=\"your.BusinessBean\"\u003e\n    \u003cproperty name=\"strProp\" value=\"${config.str}\" /\u003e\n    \u003cproperty name=\"intProp\" value=\"${config.int}\" /\u003e\n\u003c/bean\u003e\n```\n由于spring对多个placeholder的支持不太好，需要仔细配置order，所以建议使用SPEL方式来配置\n#### 结合spring SPEL方式注入配置\n```\n\u003cconfig:profile connect-str=\"localhost:2181\" root-node=\"/projectx/modulex\" version=\"1.0.0\"/\u003e\n\u003cconfig:group id=\"groupProp\" node=\"group\"/\u003e\n\n\u003c!-- Your business bean --\u003e\n\u003cbean class=\"your.BusinessBean\"\u003e\n    \u003cproperty name=\"strProp\" value=\"#{groupProp['config.str']}\" /\u003e\n    \u003cproperty name=\"intProp\" value=\"#{groupProp['config.int']}\" /\u003e\n\u003c/bean\u003e\n```\n\n### 更多\n如果您已经读到这儿了，辛苦回到页首给项目点个star吧，让更多的人可以关注到它 -_-\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdangdangdotcom%2Fconfig-toolkit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdangdangdotcom%2Fconfig-toolkit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdangdangdotcom%2Fconfig-toolkit/lists"}