Configuring Spring Bean to Re-Use Its Own Properties?

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!

Answers


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 Bean and AnotherBean - 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 AnotherBean would get instantiated before aBean and 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:

<property name="propertyThree" value="${aBean.propertyOne}"/>

You can create "propertyOne" as a separate bean.

and reference that from aBean , and your inline bean.

<bean id="propertyOne" class="java.lang.String">
    <constructor-arg><value>"blabla"</value></constructor-arg>
</bean>

<bean id="aBean" class="com.test.SimpleBean">
<property name="name" ref="firstProperty" />
<property name="newBean">
    <bean class="com.test.OtherSimplwBean">
        <property name="otherName" ref="propertyOne" />
    </bean>
</property>


Need Your Help

How do you get value of a pixel from a webcam in Pure Data?

webcam puredata

I'm new to Pure Data and am really impressed with it so far.