springpropertiesjavabeanswritable

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


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?

Solution

  • 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.