spring NotWritablePropertyException异常

Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'userDao' of bean class [tarena.service.UserServiceImpl]: Bean property 'userDao' 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:801)
	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:651)
	at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:78)
	at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:59)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1276)
	... 16 more

错误原因已经很明显了,userDao没有一个set方法,在tarena.service.UserServiceImpl中添加如下代码即可

private UserDAO userDao;
    
	public void setUserDao(UserDAO userDao) {
		this.userDao = userDao;
	}


原文地址:https://www.cnblogs.com/suncoolcat/p/3313309.html