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,spring- rocketmq
或 application. yml文件配置
# 项目ID
app:
id: gateway-server
apollo:
bootstrap:
enabled: true # 启动阶段就注入配置(提高优先级)
# 使用哪些命名空间中的配置项
namespaces: application,micro_service.spring-boot-http,micro_service.spring-eureka,micro_service.spring-hystrix,micro_service.spring-ribbon,micro_service.spring-boot-redis
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