好吧,我已经有一段时间没有使用Spring了,所以我有点生疏了。不确定我是否错过了这一切。我的 Spring 的 appContext.xml 声明“在 com.ztp.spring.injection.TestBean 类中没有找到属性 testBean 的 setter ”。
这是 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");
}
}
我几个月前开发了另一个程序,它的逻辑是相同的,并且它有效。所以我不确定我错过了什么。
如果它已经得到答复或者您需要更多信息,请直接说出来,我想弄清楚这一点。
提前谢谢您。
最佳答案
方法名称拼写错误。你的意思是这样的:
public void setTestBean(TestBean testBean) {
this.testBean = testBean;
}
您有setTestClass
。这将违反 JavaBean conventions .
关于java - 在类 * 中找不到属性 * 的 setter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19748013/