16.spring源码之@PropertySource注解

上篇文字讲了@Component注解,我们接着往后面的代码看,回到doProcessConfigurationClass()方法

1.doProcessConfigurationClass()方法

2.进入processPropertySource()方法

2.1进入resolveRequiredPlaceholders()方法

进入resolveRequiredPlaceholders()方法

进入到doResolvePlaceHolders()方法

进入replacePlaceholders()方法,这个方法在讲属性文件的时候说过,这里就是把${key}替换成value值,替换占位符,属性文件可能存在这种引用

2.2进入addPropertySource()方法

其实@PropertySource注解就相当于xml配置文件中的<context:properties-placeholder location="classpath:application.properties">

3.应用

1.创建属性文件application.properties

2.创建一个类使用@PropertySource注解

3.测试

posted @ 2021-08-15 15:20  福福猿  阅读(141)  评论(0)    收藏  举报