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

I have a spring web application. I defined a bean controller that accepts a bean property as a property. The bean service also accepts Tao. Tao is verified and working fine. Now the problem is with the service. In fact, I would take care of the setters!

what is the problem?

Bean controller:

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

Class of service:

  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; } } 

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? 
+4
source share
3 answers

ListTypeController does not have a property of the corresponding type to receive the typeService bean, otherwise the setting for this property is incorrect. Note that if you have ListTypeController and your ListTypeController indicates the type as TypeServiceImpl , this may be due to the fact that you must access the bean by its interface type typeService . The proxy for your typeService will be typeService , but not TypeServiceImpl .

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

+4
source

In my case, I named my name as: isMyProperty and is in the prefix that caused the problem. I needed to change the name to myProperty .

+1
source

In my case, this was due to the fact that I had the correct setter and getter, but each with a different type.

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

For some reason, Spring (v3) is confused.

0
source

All Articles