Bean property 'xxDao' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'xxDao' of bean class [com.xx.framework.exam.service.impl.xxServiceImpl]: Bean property 'xxDao' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:793)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:645)
如上报错是由于 注入dao名和注入service名写错了,必须要保证程序中的getter setter方法中的命名和注入名一致
applicationContext.xml中的配置如下:...
<bean id="xxDao" class="com.xx.daoimp.xxDaoImp" scope="singleton">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 把service交给Dao -->
<bean id="xxService" class="com.xx.serviceimp.xxServiceImp">
<property name="xxDao" ref="xxDao"></property>
</bean>
<bean id="xx" class="com.starheld.action.xxAction">
<property name="xxservice" ref="xxService"></property>
</bean>
<bean id="xx" class="com.xx.framework.exam.action.xxAction">
<property name="xxService">
<ref bean="xxService" />
</property>
</bean>
...
代码如下:
public class xxAction extends ActionSupport {
private User sser ;
private xxService xxservice;
public xxService getxxservice() {
return xxservice;
}
public void setxxservice(xxService xxservice) {
this.xxservice = xxservice;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public class xxServiceImp implements xxService {
public xxDao xx;
public boolean find(String username) {
// 查找用户名是否存在
return xx.find(username);
}
public void savexx(User user) {
// 保存注册信息
this.xx.SaveUser(user);
}
public xxDao getxx() {
return xx;
}
public void setxx(xxDao xx) {
this.xx = xx;
}
}