Bean property 'xxx' is not writable or has an invalid setter method

拟墨画扇 提交于 2019-12-07 05:06:15

问题


I have spring web application. I have defined the controller bean which takes the bean of service as property. Also service bean takes the Dao. Dao is tested and working fine. Now the problem with service. Actually i'd make sure about the setters there !

so what is the problem ?

Controller Bean :

<bean id="listTypeController" class="me.web.servlet.controller.ListTypeController">
<property name="typeService" ref="typeService" />
</bean>  

Service Bean :

<bean id="typeService"class="me.general.service.impl.TypeServiceImpl">
<property name="genericDao" ref="genericDao" />
<property name="typeDao" ref="typeDao" />
</bean>

Service class:

 public class TypeServiceImpl implements TypeService {

    private TypeDao typeDao;
        private GenericDao genericDao;
    public TypeDao getTypeDao() {
    return typeDao;
}

public GenericDao getGenericDao() {
    return genericDao;
}
public void setTypeDao(TypeDao typeDao) {
    this.typeDao = typeDao;
}

public void setGenericDao(GenericDao genericDao) {
    this.genericDao = genericDao;
}
}

List Controller:

public class ListTypeController {

public static final String SEARCH_TYPE_FORM_ATTRIBUTE_NAME = "SearchTypeForm";

private TypeService typeService;

@ModelAttributeSEARCH_TYPE_FORM_ATTRIBUTE_NAME)
public SearchTypeForm createForm() {
    SearchTypeForm form = new SearchTypeForm();
    form.setPageSize(SystemConfiguration.getCurrentConfiguration().getDefaultPageSize());
    form.setActive(Boolean.TRUE);
    return form;
}

@RequestMapping("/administration/types")
public String listTypes(@ModelAttribute(SEARCH_TYPE_FORM_ATTRIBUTE_NAME) SearchTypeForm form,
                             Model model) {
    Page<Type> all = typeService.findTypes(form);
    model.addAttribute("all", all);
    return "/master/general/List";
}


public void setTypeServic(TypeService typeService) {
    this.typeService = typeService;
}
}

The Error :

Invalid property 'typeService' of bean class 
[me.web.servlet.controller.ListTypeController]: 
Bean property 'typeService' is not writable or has an invalid setter method.
Does the parameter type of the setter match the return type of the getter?

回答1:


ListTypeController doesn't have a property of the appropriate type to receive the typeService bean, or else the setter for that property is malformed. Note that if you have some proxying going on and your ListTypeController specifies the type as TypeServiceImpl, then it may be because you should be referring to the bean by its interface type, TypeService. A proxy of your typeService would be a TypeService, but not a TypeServiceImpl.

Update: Based on your new code: setTypeServic should be setTypeService, or else your property name is actually typeServic.




回答2:


In my case i named my propery as: isMyProperty and is in prefix caused an issue. I had to change the name to myProperty.




回答3:


In my case it was because I had correct setter and getter but each with different type.

My setter took String and parsed it to target enum type and my getter returned directly the enum.

For some reason Spring (v3) got confused.



来源:https://stackoverflow.com/questions/14888588/bean-property-xxx-is-not-writable-or-has-an-invalid-setter-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!