Apollo配置中心 + springboot 简单使用

Apollo配置中心 + springboot 简单使用

引入依赖

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

添加配置

apollo.bootstrap.enabled=true
# will inject 'application', 'FX.apollo' and 'application.yml' namespaces in bootstrap phase
apollo.bootstrap.namespaces=application
apollo.bootstrap.eagerLoad.enabled=true
#配置configservice地址
apollo.meta=http://localhost:8091
# test
app.id=SampleApp

简单使用

import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

@SpringBootApplication
@EnableScheduling
@Slf4j
public class OppositeApplication {

    @Value("${test:1}")
    public String test;

    @Value("${test1:1}")
    public String test1;

    @ApolloConfig("application")
    private Config anotherConfig;

    @Scheduled(cron = "0/1 * * * * ?")
    public void test(){
        log.info("定时输出配置:test:{}",test);
        log.info("定时输出配置:test1:{}",test1);
        log.info("定时输出配置:anotherConfig测试test:{}",anotherConfig.getProperty("test","test"));
        log.info("定时输出配置:anotherConfig测试test1:{}",anotherConfig.getProperty("test1","test1"));
    }
    
    public static void main(String[] args) {
        SpringApplication.run(OppositeApplication.class, args);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值