<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN/EN"
"http://www.springframework.org/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!</value>
</property>
</bean>
</beans>
helloBean.helloWord=Welcome!helloBean对应于XML定义档中的某个Bean的id值,当中的helloWord设定将覆盖XML中的helloWord属性设定,如果您执行下面的程序,最后会显示"Welcome!",而不是"Hello!":
package onlyfun.caterpillar;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class SpringDemo {
public static void main(String[] args) throws InterruptedException {
ApplicationContext context =
new FileSystemXmlApplicationContext("beans-config.xml");
HelloBean hello =
(HelloBean) context.getBean("helloBean");
System.out.println(hello.getHelloWord());
}
}