比较spring ref和idref与编码示例

时间:2018-10-09 12:02:49

标签: java spring inversion-of-control

我正在阅读有关Spring IOC容器的信息,并在定义对bean的引用时遇到了ref和idref术语。但是我不明白它们之间有什么区别。尽管在stackoverflow上也存在一些类似的问题,但是它们并不是重点。

接着是spring applicationContext.xml文件

        <?xml version="1.0" encoding="UTF-8"?>
        <beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans             http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">


<bean name="tokenService" class="com.services.TokenService" />

<bean name="messageBroker,mBroker,MyBroker" class="com.components.MessageBroker">
    <property name="tokenBluePrint">
        <idref bean="tokenService" />
    </property>
    <property name="brokerId">
        <null />
    </property>
    <property name="brokerName">
        <value></value>
    </property>
</bean>

请任何人提供任何好的解释。

0 个答案:

没有答案