[toc]
选择DEV环境,新增配置, 我这里有测试过,所以dev环境多了个gzywtest-c1集群,默认情况下,点击环境都是选择default配置
获取集群下所有Namespace信息接口
···
curl -H 'Authorization:ab5a901872858535afb48f4da1f7c1c5be522de5' /
-H 'Content-Type:application/json;charset=UTF-8' /
http://192.168.1.1:8080/openapi/v1/envs/dev/apps/900001/clusters/default/namespaces/applicationhttp://192.168.1.1:8080/openapi/v1/envs/dev/apps/900001/clusters/default/namespaces/application
···
{ "appId": "900001", "clusterName": "default", "namespaceName": "application", "comment": "default app namespace", "format": "properties", "isPublic": false, "items": [{ "key": "redis_host", "value": "127.0.0.1", "dataChangeCreatedBy": "apollo", "dataChangeLastModifiedBy": "apollo", "dataChangeCreatedTime": "2018-07-04T16:55:54.000+0800", "dataChangeLastModifiedTime": "2018-07-04T16:55:54.000+0800" }, { "key": "timeout", "value": "8000", "comment": "", "dataChangeCreatedBy": "apollo", "dataChangeLastModifiedBy": "apollo", "dataChangeCreatedTime": "2018-07-09T11:07:24.000+0800", "dataChangeLastModifiedTime": "2018-07-09T11:13:36.000+0800" }, { "key": "batch", "value": "9000", "comment": "", "dataChangeCreatedBy": "apollo", "dataChangeLastModifiedBy": "apollo", "dataChangeCreatedTime": "2018-07-09T11:20:02.000+0800", "dataChangeLastModifiedTime": "2018-07-09T15:38:02.000+0800" }], "dataChangeCreatedBy": "apollo", "dataChangeLastModifiedBy": "apollo", "dataChangeCreatedTime": "2018-07-04T16:11:00.000+0800", "dataChangeLastModifiedTime": "2018-07-04T16:11:00.000+0800" }
* 结构url的参数规则如下: ![](http://i2.51cto.com/images/blog/201807/13/b33c8b06860ad718981228618a33138f.jpg?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) * Api更多文档参考,参考 https://github.com/ctripcorp/apollo/wiki/Apollo%E5%BC%80%E6%94%BE%E5%B9%B3%E5%8F%B0 --- ### Java的接入方式 * 参考 https://github.com/ctripcorp/apollo/wiki/Java%E5%AE%A2%E6%88%B7%E7%AB%AF%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97 其实官方的源包下已经包含一个apollo-demo的项目,如果你在看了上一篇的部署apollo项目后,应该记得脚本最后有一个上传本地架包到maven的步骤,这个就是如果想进行java搭建必须的操作,需要将编译好的架包上传到私有源上去. 因为我实在没调通官方的demo项目,所以根据官方的demo项目自己创建一个新的项目来调试,简单讲述下实现的代码,后面提供下载 1. 打开 http://start.spring.io/ ,输入简单的选项,点击生成项目后下载到本地 ![](http://i2.51cto.com/images/blog/201807/13/79fe86478a3f2a122ebd541f9d395e0b.jpg?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) 1. 引入eclipse ![](http://i2.51cto.com/images/blog/201807/13/1e63406fb89585f1625fbfb94bf732d9.jpg?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) * 我这里引入过,所以不能再引入,正常输入目录后,eclipse扫描后点击finish就可以引入 ![](http://i2.51cto.com/images/blog/201807/13/a5c9912039dba831f7684776a6dadae5.jpg?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) 1. 在pom.xml中添加下列包 ```xml <!-- 引入的包##################### --> <dependency> <groupId>com.ctrip.framework.apollo</groupId> <artifactId>apollo-client</artifactId> <version>0.11.0-SNAPSHOT</version> </dependency> <dependency> <groupId>com.ctrip.framework.apollo</groupId> <artifactId>apollo-core</artifactId> <version>0.11.0-SNAPSHOT</version> </dependency> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>25.1-jre</version> </dependency> <!-- https://mvnrepository.com/artifact/com.google.inject/guice --> <dependency> <groupId>com.google.inject</groupId> <artifactId>guice</artifactId> <version>4.2.0</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> </dependency>
将官方apollo-demo下的 com.ctrip.framework.apollo.demo 拷贝到我们的demo下,这里仅测试官方推荐的java读取方式,删除多余的文件,最后的结构如下
#我的是window下测试,所以在
在eclipse 的 META-INF目录下创建一个 app.properties文件添加内容 : app.id=900001
在 pom.xml上右键选择run - maven install ,然后在 AnnotationApplication 右键run - spring boot app
运行的输出应该能看到如下输出
* 在console回车会看到
发布配置
可以看到console输出中,timeout已经变更了值