这是appContext.xml文件:
<bean id="myTestBean" class="com.ztp.spring.injection.TestBean" />
<bean id="myTestClass" class="com.ztp.spring.injection.TestClass">
<property name="testBean" ref="myTestBean" />
</bean>
以下是TestClass.java文件的全部内容:
public class TestClass {
TestBean testBean;
public void setTestClass(TestBean testBean) {
this.testBean = testBean;
}
public void fillBean() {
testBean.setId(5);
testBean.setTestAnimal("sheltie");
}
}
我有几个月前我工作过的另一个程序,它的逻辑方面也一样,并且有效。所以我不确定我错过了什么。
如果它已经回答了或者您需要更多信息,请说明一下,我想解决这个问题。
提前谢谢。
答案 0 :(得分:5)
方法名称中的错字。你的意思是:
public void setTestBean(TestBean testBean) {
this.testBean = testBean;
}
你有setTestClass
。这会违反JavaBean conventions。
答案 1 :(得分:2)
方法名称应与bean的属性名称匹配:
public void setTestBean(TestBean testBean) {