Springboot
目录
springboot知识总结
bootstrap phase
bootstrap阶段是springboot中为应用容器准备启动环境的阶段。该阶段最先运行,会产生BootstrapContext,为ApplicationContext准备配置文件,加载其他需要资源。BootstrapContext为ApplicationContext的父容器,其中的配置属性和Bean对于子容器均可见。该阶段会读取bootstrap.yml(properties)配置文件并存储于BootstrapContext,以便与ApplicationContext相关配置隔离。
应用:
- 配置远程配置中心地址并从中获取应用配置,如Apollo和spring cloud config
- 可以作为测试上下文所需资源的承载环境,如**testcontainers-spring-boot**
注意事项:
Bootstrap相关自动配置Bean不能放在应用上下文扫描路径下,避免不必要的重复Bean创建。
Bootstrap bean由META-INF/spring.factories下org.springframework.cloud.bootstrap.BootstrapConfiguration文件控制
Application bean由META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports文件控制
springboot2.4.x后需要由spring-cloud-starter-bootstrap依赖开启Bootstrap阶段