0
votes

I want to know how to inject attribute of an Object to another Spring bean in Spring XML configurations? I have declared a bean in configuration file and I want to inject attribute of that bean into another bean.

Update: Here is the configurations I tried in the spring.xml file.

<bean id="cFactoryBean" class="org.springframework.data.cassandra.config.CassandraClusterFactoryBean>
        <property name="contactPoints" value="${cassandra.contactpoints}" />
        <property name="port" value="${cassandra.port}" />
</bean>

<bean id="sFactoryBean" class="org.springframework.data.cassandra.config.CassandraSessionFactoryBean>
        <property name="cluster" value="${cFactoryBean.object}" />
        <property name="keyspaceName" value="${cassandra.keyspace}" />
        <property name="converter" ref="cConverterBean" />
</bean>

I have created cFactoryBean bean and I want to inject object property of cFactoryBean to the 'cluster' property in the sFactoryBean.

1
Add what you have tried. - Jens
@Jens I have added a sample code. - ChannaB
I can not see an object property in cFactoryBean - Jens

1 Answers

0
votes

In the following example the attribute connectionManager of the class Dao refers to the spring bean dbConnectionManager.

<bean id="feedbackDao" class="com.foo.Dao" 
    <property name="connectionManager" ref="dbConnectionManager" />
</bean>

<bean id="dbConnectionManager" class="com.foo.dao.ConnectionManager" />