我的spring学习笔记15-容器扩展点之PropertyOverrideConfigurer
PropertyOverrideConfigurer类似于PropertyPlaceholderConfigurer,但是与后者相比,前者对于bean属性可以有缺省值或者根本没有值。也就是说如果properties文件中没有某个bean属性的内容,那么将使用上下文(配置的xml文件)中相应定义的值。如果properties文件中有bean属性的内容,那么就用properties文件中的值来代替上下文中的bean的属性值。
首先看一下配置文件,代码如下:
<bean value="propertyOverrideHolder.properties"/> </bean> <bean id ="student" name="code">public class PropertyOverrideConfigurerDemo { public static void main(String[] args) { ApplicationContext ctx = new ClassPathXmlApplicationContext("propertyOverrideHolder.xml"); Student student = (Student) ctx.getBean("student"); System.out.println(student.getAge()); System.out.println(student.getBirth()); System.out.println(student.getName()); }}