简体   繁体   English

春天没有依赖注入

[英]dependency injection not behaving in spring

Simply I have 2 classes. 简单来说,我有2节课。 Questions.java and Answers.java I am just trying to inject answers object into Questions. Questions.java和Answers.java我只是想将Answers对象注入Questions。 This is my beans.xml file 这是我的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>

When i output to the console in netbeans i just get this line 当我在netbeans中输出到控制台时,我得到这一行

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

when surely i should get answers=answers injected into it. 当然可以,我应该将answer = answers注入其中。 literally have no idea why this wont work. 从字面上不知道为什么这行不通。

[SOLVED]. [解决了]。 foolish error, just forgot to put the correct stuff in the toString() method. 愚蠢的错误,只是忘记将正确的内容放入toString()方法中。 apologies for a horrible error everyone! 道歉,大家都犯了一个可怕的错误!

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

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