There must be some subtlety in the way my class variables are being looked at by Spring. I've reviewed the associated files and am unable to spot where I am being inconsistent with something. Can you help me find what it is?
The error I'm getting is:
org.springframework.beans.NotWritablePropertyException: Invalid property 'memberVariableClass' of bean class [ClassName]: Bean property 'memberVariableClass' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
Here's the top-level bean, ClassName.java:
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class ClassName {
private MemberVariableClass memberService;
// private EditorService spanishEditorService;
public ClassName() {
}
// public ClassName(MemberVariableClass memberVariableClassArgument) {
// this.memberService = memberVariableClassArgument;
// }
@ResponseBody
@RequestMapping(value = "/")
public String helloWorld()
{
return "Hello world!";
}
public void setMemberService(MemberVariableClass memberService) {
this.memberService = memberService;
}
}
Here's the MemberVariableClass interface followed by its implementation:
/*
* The old EditorService.
* Probably be best if name was MemberVariableClassInterface... for now.
*/
public interface MemberVariableClass {
public String dummyMethod();
public String getAttribute();
}
public class MemberVariableClassImpl implements MemberVariableClass {
String attribute = "value";
public String dummyMethod() {
return "Hi I'm a dummy method.";
}
public String getAttribute() {
return this.attribute;
}
}
and finally, here's the servletContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://ift.tt/GArMu6"
xmlns:xsi="http://ift.tt/ra1lAU"
xmlns:mvc="http://ift.tt/1bHqwjR"
xsi:schemaLocation="http://ift.tt/GArMu6
http://ift.tt/1cnl1uo
http://ift.tt/1bHqwjR
http://ift.tt/1kF4x7W">
<mvc:annotation-driven />
<bean name="className" class="ClassName">
<property name="memberService" ref="memberVariableClassImpl" />
</bean>
<bean name="memberVariableClassImpl" class="MemberVariableClassImpl" />
</beans>
Aucun commentaire:
Enregistrer un commentaire