我有春季网络应用程序.我已经定义了控制器bean,它将服务的bean作为属性.服务bean也需要Dao. Dao经过测试并且工作正常.现在服务问题.其实我会确定那里的二传手!
那有什么问题?
控制器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,否则该属性的setter格式不正确.请注意,如果您正在进行某些代理并且ListTypeController将类型指定为TypeServiceImpl,那么可能是因为您应该通过其接口类型TypeService引用该bean. typeService的代理是TypeService,但不是TypeServiceImpl.
更新:根据您的新代码:setTypeServic应该是setTypeService,否则您的属性名称实际上是typeServic.