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
文件的位置是在这里设置。再回答什么时候
如果了解一点
spring
源码,会看到spring
容器启动都是通过调用refresh
方法实现。在refresh
中有一个方法调用invokeBeanFactoryPostProcessors(beanFactory)
的作用就是去实现BeanFactoryPostProcessor
这个接口的方法而
PropertyPlaceholderConfigurer
的一个父类PropertyResourceConfigurer
就实现了这个接口,所以spring
在完成BeanFactory
的初始化时就会调用上述提到的方法。