Skip to content

Latest commit

 

History

History
 
 

lab05

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

实验5:Apollo Client和Spring Boot集成

一、实验步骤

1~6. 同实验4

Spring Boot有一些场景需要配置在更早的阶段注入

  • 使用@ConditionalOnProperty的场景
  • 是有一些spring-boot-starter在启动阶段就需要读取配置做一些事情(如spring-boot-starter-dubbo)

启动方式:

// 启动
apollo.bootstrap.enabled=true
// 注入多个名字空间
apollo.bootstrap.namespaces = application,TEST1.apollo

7. 条件属性(ConditionalOnProperty)

@ConfigurationProperties如果需要在Apollo配置变化时自动更新注入的值,需要配合Spring Cloud的RefreshScope使用

  • Annotation
// 条件属性
@ConditionalOnProperty
// 自动刷新
@RefreshScope
// 监听Apollo事件
@ApolloConfigChangeListener

二、参考

  1. 代码SpringBootSampleApplication
  2. 文档Java客户端使用指南