1、编写配置文件
# classpath:/cn/java/demo/beantag/placeholder0.properties
# beanPlaceholderTest0 \u7684\u52A8\u6001\u914D\u7F6E
beanPlaceholderTest0.factoryMethod=getCreatedByFactoryBean
beanPlaceholderTest0.scope=prototype
beanPlaceholderTest0.constructorArg0=1
beanPlaceholderTest0.constructorArg1=username1_beanPlaceholderTest0
beanPlaceholderTest0.property1=property1_beanPlaceholderTest0
# beanPlaceholderTest1 \u7684\u52A8\u6001\u914D\u7F6E
beanPlaceholderTest1.parent=standardBean0
beanPlaceholderTest1.class=cn.java.demo.beantag.bean.StandardBean
beanPlaceholderTest1.scope=prototype
beanPlaceholderTest1.constructorArg0=1
beanPlaceholderTest1.beanName=beanName_beanPlaceholderTest1_hi
2、注册配置文件到PropertyPlaceholderConfigurer
<!-- 替换BeanDefinition中的占位符 -->
<!--
这个是一个实现org.springframework.beans.factory.config.BeanFactoryPostProcessor接口的bean,
机制:在beanFactory解析完所有的BeanDefinition后,本bean会扫描所有的BeanDefinition,替换BeanDefinition中的占位符(从properties文件中查找值)
-->
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="order" value="0" />
<property name="locations">
<list>
<value>classpath:/cn/java/demo/beantag/placeholder0.properties</value>
</list>
</property>
</bean>
3、使用占位符
<bean id="beanPlaceholderTest0" factory-bean="factoryBean0" factory-method="${beanPlaceholderTest0.factoryMethod}" scope="${beanPlaceholderTest0.scope}">
<constructor-arg index="0" type="java.lang.Integer" name="userid" value="${beanPlaceholderTest0.constructorArg0}"/>
<constructor-arg index="1" type="java.lang.String" name="username" value="${beanPlaceholderTest0.constructorArg1}"/>
<property name="property1" value="${beanPlaceholderTest0.property1}" />
</bean>
<bean id="beanPlaceholderTest1" parent="${beanPlaceholderTest1.parent}" class="${beanPlaceholderTest1.class}" scope="${beanPlaceholderTest1.scope}">
<constructor-arg index="0" type="java.lang.Integer" name="beanId" value="${beanPlaceholderTest1.constructorArg0}" />
<property name="beanName" value="${beanPlaceholderTest1.beanName}" />
</bean>