SpringBoot快速集成Apollo配置中心

1.引入依赖

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

2.添加配置

#    app.id:AppId是应用的身份信息,是配置中心获取配置的一个重要信息。
#    apollo.bootstrap.enabled:在应用启动阶段,向Spring容器注入被托管的application.properties文件的配置信息。
#    apollo.bootstrap.eagerLoad.enabled:将Apollo配置加载提到初始化日志系统之前。
#    my.test: 等等演示读取Apollo中的配置
​
server:
  port: 8761
​
app:
  id: springboot-apollo
apollo:
  meta: http://127.0.0.1:8080
  bootstrap:
    enabled: true
    eagerLoad:
      enabled: true
      
my:
  test: 1

3.测试类

@RestController
public class HelloController {
    @Value("${my.test}")
    String test;
​
    @GetMapping("hi")
    public String hi(String name) {
        System.out.println("name:" + name);
        return test + ":"+name;
    }
​
}

4.Apollo配置

 

5.测试

启动项目,访问http://localhost:8761/hi?name=yfy

 

可以看到读取到了apollo中的对应配置。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章