依赖注入在春天不表现

时间:2014-11-13 14:12:33

标签: spring dependency-injection

我只有2节课。 Questions.java和Answers.java 我只是想把答案对象注入问题。 这是我的beans.xml文件

<bean id="questions" class="main.Questions">
    <constructor-arg value="0000"></constructor-arg>
    <constructor-arg value="What is the question?"></constructor-arg>
    <constructor-arg value="threading"></constructor-arg>
    <property name="correctAnswer" value="deadlock"></property>
    <property name="answers" ref="answers"></property>
</bean>

<bean id="answers" class="main.Answers">
<constructor-arg value="0000"></constructor-arg>
<constructor-arg value="LiveLock"></constructor-arg>

</bean>

当我在netbeans中输出到控制台时,我只得到这一行

Question [questionId=0, question=What is the question?, category=threading, correctAnswer=deadlock]

当肯定我应该得到答案=注入其中的答案。 字面上不知道为什么这不起作用。

1 个答案:

答案 0 :(得分:0)

[解决]。愚蠢的错误,只是忘了把正确的东西放在toString()方法中。为每个人的可怕错误道歉!