SpringBoot集成Apollo

SpringBoot集成Apollo

Apollo部署相关

  • 1、 创建SpringBoot项目

springboot版本


  org.springframework.boot
  spring-boot-starter-parent
  2.1.4.RELEASE
   

在pom引入Apollo客户端依赖


    com.ctrip.framework.apollo
    apollo-client
    1.1.1

  • 2、 application.properties 配置appId和configservice地址

我部署在公司内网192.168.0.114服务器上

# 应用ID(在Apollo服务端新增项目添加的应用ID)
app.id=123456
# apollo-configservice地址
apollo.meta=http://192.168.0.114:8080/
  • 3、项目发布设置配置信息

SpringBoot集成Apollo_第1张图片

SpringBoot集成Apollo_第2张图片

SpringBoot集成Apollo_第3张图片

  • 4、客户端进行获取

  • 基于注解方式进行获取,在Application的main方法上加上@EnableApolloConfig注解

SpringBoot集成Apollo_第4张图片

  • 新建Controller进行测试

SpringBoot集成Apollo_第5张图片

  • 使用Postman进行测试

SpringBoot集成Apollo_第6张图片

  • 修改并且发布,客户端不进行重启

SpringBoot集成Apollo_第7张图片

  • 修改配置信息,发布成功,客户端会监听到该事件,在控制台输出日志

输入图片说明

  • 第二次测试,在不重启客户端的情况下,获取更新数据成功

SpringBoot集成Apollo_第8张图片

你可能感兴趣的:(Apollo-2019)