Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘userService’ defined in class path resource [spring-sys.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property ‘userDAO’ of bean class [com.zking.login.sys.service.impl.UserService]: 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?
错误写法:
根据org.springframework.beans.NotWritablePropertyExcep tion 初步分析是spring配置文件中配置问题 或配置文件中某个地方写的不对。
<bean id="userService" class="com.zking.login.sys.service.impl.UserService">
<property name="userDAO">
<ref bean="userDAO" />
</property>
</bean>
而 java类中我写set方法中是这么写的
private IUserDao userdao;
public UserService() {
}
public IUserDao getUserdao() {
return userdao;
}
public void setUserdao(IUserDao userdao) {
this.userdao = userdao;
}
set 中的属性userdao和 property name=“userdao” 写的不一致
解决方法:
<bean id="userService" class="com.zking.login.sys.service.impl.UserService">
<property name="userdao">
<ref bean="userdao" />
</property>
</bean>
将修改成和set一致 即可。