|
From: Tom T. <tom...@pr...> - 2004-07-09 12:35:59
|
Hello Juergen, > parent can even omit the bean class completely, simply specifying common > properties for children: > > <bean id="inheritedTestBeanWithoutClass"> > <property name="name"><value>parent</value></property> > <property name="age"><value>1</value></property> > </bean> > > <bean id="inheritsWithClass" > class="org.springframework.beans.DerivedTestBean" > parent="inheritedTestBeanWithoutClass" init-method="initialize"> > <property name="name"><value>override</value></property> > <!-- age should inherit value of 1 from parent --> > </bean> > > Of course, such a parent bean cannot get instantiated on its own: It's > just a template that serves as parent definition for children. > preInstantiateSingletons will ignore such beans without class and parent > completely. I've accidentally noticed that this doesn't work when using a PropertiesBeanDefinitionReader. This bean definition file: inheritedTestBeanWithoutClass.name = parent inheritedTestBeanWithoutClass.age = 1 inheritsWithClass.class = org.springframework.beans.DerivedTestBean inheritsWithClass.parent = inheritedTestBeanWithoutClass inheritsWithClass.init-method = initialize inheritsWithClass.name = override # age should inherit value of 1 from parent results in this exception: org.springframework.beans.factory.BeanDefinitionStoreException: Error registering bean with name 'inheritedTestBeanWithoutClass' defined in file [...]: Either 'class' or 'parent' is required at org.springframework.beans.factory.support.PropertiesBeanDefinitionReader.registerBeanDefinition(PropertiesBeanDefinitionReader.java:368) at org.springframework.beans.factory.support.PropertiesBeanDefinitionReader.registerBeanDefinitions(PropertiesBeanDefinitionReader.java:269) at org.springframework.beans.factory.support.PropertiesBeanDefinitionReader.loadBeanDefinitions(PropertiesBeanDefinitionReader.java:159) at org.springframework.beans.factory.support.PropertiesBeanDefinitionReader.loadBeanDefinitions(PropertiesBeanDefinitionReader.java:140) The same configuration in xml does work when using an XmlBeanDefinitionReader. Kind regards, Tom. |