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

3

5

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?
Corinacorine answered 15/2, 2013 at 5:7 Comment(2)
What's the relevant code of ListTypeController then?Parthenos
@Parthenos the code is posted now !Corinacorine
P
6

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.

Portillo answered 15/2, 2013 at 5:14 Comment(0)
M
3

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

Middlebuster answered 26/8, 2015 at 10:58 Comment(0)
B
1

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.

Biedermeier answered 7/3, 2017 at 12:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.