Bean属性"xxx"不可写或具有无效的setter方法 [英] Bean property 'xxx' is not writable or has an invalid setter method

查看:144
本文介绍了Bean属性"xxx"不可写或具有无效的setter方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有spring Web应用程序.我定义了控制器bean,它将服务bean作为属性.另外服务豆拿刀. Dao经过测试,工作正常.现在的服务问题.其实我会确保那里的二传手!

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 !

那是什么问题?

Controller Bean:

Controller Bean :

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

服务Bean:

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

服务类别:

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

列表控制器:

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

错误:

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?

推荐答案

ListTypeController没有合适类型的属性来接收typeService bean,否则该属性的设置程序格式错误.请注意,如果正在进行某种代理并且ListTypeController将类型指定为TypeServiceImpl,则可能是因为您应该通过其接口类型TypeService来引用该bean. typeService的代理将是TypeService,而不是TypeServiceImpl.

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.

更新:根据您的新代码:setTypeServic应该为setTypeService,否则您的属性名称实际上为typeServic.

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

这篇关于Bean属性"xxx"不可写或具有无效的setter方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆