简体   繁体   English

将对象属性注入到Spring bean

[英]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? 我想知道如何在Spring XML配置中将对象的属性注入另一个Spring bean? I have declared a bean in configuration file and I want to inject attribute of that bean into another bean. 我已经在配置文件中声明了一个bean,我想将该bean的属性注入另一个bean。

Update: Here is the configurations I tried in the spring.xml file. 更新:这是我在spring.xml文件中尝试的配置。

<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. 我已经创建了cFactoryBean bean,并且想要将cFactoryBean的object属性注入sFactoryBean中的'cluster'属性。

In the following example the attribute connectionManager of the class Dao refers to the spring bean dbConnectionManager. 在以下示例中,类Dao的属性connectionManager引用了Spring Bean dbConnectionManager。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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