java - PropertyPlaceholderConfigurer如何读取配置文件路径的?
本文介绍了java - PropertyPlaceholderConfigurer如何读取配置文件路径的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
PropertyPlaceholderConfigurer如何读取配置文件路径的
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>/WEB-INF/mail.properties</value>
<value>classpath:conf/jdbc.properties</value
</list>
</property>
</bean>
这个配置中的locations,我在PropertyPlaceholderConfigurer中没有发现有这个属性,dubug进行查看PropertyPlaceholderConfigurer发现Properties类中已经有jdbc.properties中的数据了。
我现在想知道PropertyPlaceholderConfigurer加载conf/jdbc.properties属性文件是在什么时候哪里做的
解决方案
先回答在哪PropertiesLoaderSupport
这个抽象类,是PropertyPlaceholderConfigurer
父类,Properties
文件的位置是在这里设置。
public void setLocation(Resource location) {
this.locations = new Resource[] {location};
}
再回答什么时候
如果了解一点spring
源码,会看到spring
容器启动都是通过调用refresh
方法实现。在refresh
中有一个方法调用invokeBeanFactoryPostProcessors(beanFactory)
的作用就是去实现BeanFactoryPostProcessor
这个接口的方法
void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException;
而PropertyPlaceholderConfigurer
的一个父类PropertyResourceConfigurer
就实现了这个接口,所以spring
在完成BeanFactory
的初始化时就会调用上述提到的方法。
这篇关于java - PropertyPlaceholderConfigurer如何读取配置文件路径的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文