简体   繁体   中英

Inject object attribute to spring bean

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.

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" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM