本文主要是介绍16.spring源码之@PropertySource注解,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
上篇文字讲了@Component注解,我们接着往后面的代码看,回到doProcessConfigurationClass()方法
1.doProcessConfigurationClass()方法
![](/upload/202108/15/202108152236499162.png)
2.进入processPropertySource()方法
![](/upload/202108/15/202108152236504650.png)
2.1进入resolveRequiredPlaceholders()方法
![](/upload/202108/15/202108152236507179.png)
进入resolveRequiredPlaceholders()方法
![](/upload/202108/15/202108152236509718.png)
进入到doResolvePlaceHolders()方法
![](/upload/202108/15/202108152236512081.png)
进入replacePlaceholders()方法,这个方法在讲属性文件的时候说过,这里就是把${key}替换成value值,替换占位符,属性文件可能存在这种引用
![](/upload/202108/15/202108152236514753.png)
2.2进入addPropertySource()方法
![](/upload/202108/15/202108152236517594.png)
![](/upload/202108/15/202108152236519967.png)
其实@PropertySource注解就相当于xml配置文件中的<context:properties-placeholder location="classpath:application.properties">
3.应用
1.创建属性文件application.properties
![](/upload/202108/15/202108152236522326.png)
2.创建一个类使用@PropertySource注解
![](/upload/202108/15/202108152236524376.png)
3.测试
![](/upload/202108/15/202108152236526901.png)
这篇关于16.spring源码之@PropertySource注解的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!