微服务集成Apollo客户端
1 添加依赖
在pom.xml中添加Apollo客户端
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId>
<version>1.1.0</version>
</dependency>
2 添加配置
2.1 配置文件
- 在resources目录下新建apollo-env.properties文件
# 开发环境
dev.meta=http://localhost:8080
# 功能验收测试环境
fat.meta=http://apollo.fat.xxx.com
# 用户验收测试环境
uat.meta=http://apollo.uat.xxx.com
# 生产环境
pro.meta=http://apollo.xxx.com
- application.properties中进行如下配置
# 项目ID
app.id=account-service
# 启动阶段就注入配置(提高优先级)
apollo.bootstrap.enabled = true
# 使用哪些命名空间中的配置项
apollo.bootstrap.namespaces = application,micro_service.spring-boot-http,springrocketmq
# 服务端口
server.port=63000
2.2 启动参数
完整的VM Options如下:
-Denv=DEV -Dapollo.cluster=DEFAULT
- Environment
可以通过Java的System Property的env来指定环境: -Denv=DEV - Cluster(集群)
通过Java的System Property的apollo.cluste来指定集群: -Dapollo.cluster=DEFAULT