入门 16 - BeanFactoryPostProcessor接口 撰写Bean定义档通常使用XML来撰写,XML阶层式的组织为各种元素与属性设定来说相当的方便,然而XML文件在阅读时总是要费点心力,尤其是在文件中充满了许多定义内容时。 BeanFactoryPostProcessor.java public interface BeanFactoryPostProcessor { public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException; }
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN/EN" "http://www./dtd/spring-beans.dtd"> <beans> <bean id="configBean" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location"> <value>hello.properties</value> </property> </bean>
<bean id="helloBean" class="onlyfun.caterpillar.HelloBean"> <property name="helloWord"> <value>${helloWord}</value> </property>
.... </bean> ......
</beans>
hello.properties helloWord=Hello!Justin!
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN/EN" "http://www./dtd/spring-beans.dtd"> <beans> <bean id="configBean" class="org.springframework.beans.factory.config.PropertyOverrideConfigurer"> <property name="location"> <value>hello.properties</value> </property> </bean>
<bean id="helloBean" class="onlyfun.caterpillar.HelloBean"> <property name="helloWord"> <value>Hello!caterpillar!</value> </property>
.... </bean>
.... </beans>
hello.properties helloBean.helloWord=Hello!Justin!
|
|