springboot项目集成apollo总结

公司最近使用了携程的开源框架apollo来对配置文件进行管理,总体上来说还是非常简单的。

1.接入apollo

1.1 在yml或者properties文件中添加apollo配置

在resource目录下创建bootstrap.properties/yml或者application.properties/yml,配置内容如下:

#apollo中的服务名称
app.id=你在apollo后台中的项目唯一标示码
#注入默认application
apollo.bootstrap.enabled=true
#优先加载apollo配置 
apollo.bootstrap.eagerLoad.enabled=true
#注入多个namespace,配置在前的优先级更高
apollo.bootstrap.namespaces=profile,application

1.2将现有resource下的yml或者properties配置添加到apollo后台,并删除本地文件

1.3增加pom依赖

<dependency>
    <groupId>com.ctrip.framework.apollo</groupId>
    <artifactId>apollo-client</artifactId>
    <version>1.4.0</version>
</dependency>

1.4如果代码中有使用 @ConfigurationProperties 。通过增加以下代码来支持自动更新,同时这段代码也支持了日志级别自动更新

import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
import org.springframework.cloud.context.scope.refresh.RefreshScope;
import org.springframework.context.ApplicationContext
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值