简体   繁体   中英

No setter found for property * in class *

OK, I haven't used Spring in a while, so I'm a little rusty. Not sure if I missed something in all of this or not. My appContext.xml for Spring states that 'no setter is found for property testBean in class com.ztp.spring.injection.TestBean.

Here is the appContext.xml file:

<bean id="myTestBean" class="com.ztp.spring.injection.TestBean" />

<bean id="myTestClass" class="com.ztp.spring.injection.TestClass">
    <property name="testBean" ref="myTestBean" />
</bean>

and here is the TestClass.java file in its entirety:

public class TestClass {
    TestBean testBean;

    public void setTestClass(TestBean testBean) {
        this.testBean = testBean;
    }

    public void fillBean() {
        testBean.setId(5);
        testBean.setTestAnimal("sheltie");
    }
}

I have another program that I worked on months ago, and its the same logic-wise, and it works. So I'm not sure what I'm missing.

If its already been answer or you need more info, just say so, I'd like to figure this out.

Thank you in advance.

Typo in the method name. What you meant is this:

public void setTestBean(TestBean testBean) {
    this.testBean = testBean;
}

You had setTestClass . This would violate the JavaBean conventions .

方法名称应与Bean的属性名称匹配:

public void setTestBean(TestBean testBean) {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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