I’m fairly new to Spring and I need a bean that has two properties — the second of which is an inline bean that references the first property. Something like this:
<bean id="aBean" class="com.sample.Bean">
<property name="propertyOne" value="something" />
<property name="propertyTwo">
<bean class="com.sample.AnotherBean">
<property name="propertyThree" ref="propertyOne />
</bean>
</property>
</bean>
Making propertyOne its own bean isn’t an option here. What would be the best way to accomplish this? Thanks!
Only way that I can think of would be to create a bean for your common property and refer to this common property in both
BeanandAnotherBean– any reason why this is not an option for you?Any other way would not work, because of the dependency graph – aBean is dependent on Another Bean and so
AnotherBeanwould get instantiated beforeaBeanand would not be able to refer to a child bean property.If there had not been this dependency, you could have used Spring-EL to refer to the property: