准备工作

示例代码:

  1. @Component
  2. public class Foo {
  3. @Value("${foo.bar}")
  4. private String bar;
  5. public String getBar() {
  6. return bar;
  7. }
  8. public void setBar(String bar) {
  9. this.bar = bar;
  10. }
  11. @Override
  12. public String toString() {
  13. return "Foo{" +
  14. "bar='" + bar + '\'' +
  15. '}';
  16. }
  17. }

配置项:

  1. foo.bar=baz

在什么阶段进行 @Value 中的占位符替换?

AutowiredAnnotationBeanPostProcessor:负责处理 @Value 标注的字段。

BeanPostProcessor implementation that autowires annotated fields, setter methods, and arbitrary config methods. Such members to be injected are detected through annotations: by default, Spring’s @Autowired and @Value annotations.

AbstractBeanFactory中的 embeddedValueResolvers 在什么时候被赋值?赋什么值?

配置项加载后保存在哪里?由谁从配置项中找到占位符对应的配置项?

怎么自定义加载来自外部的配置?比如来自网络。

jasypt的实现原理是什么?

PropertySources 的顺序导致某些取值不符合期望

PropertySource 的内部实现是使用了 Environment,那么 Environment 中的配置项是从哪里来的?