严重: StandardWrapper.Throwable
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'urlMapping' defined in ServletContext resource [/WEB-INF/web-config.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userAction' defined in ServletContext resource [/WEB-INF/web-config.xml]: Cannot resolve reference to bean 'userService' while setting bean property 'userService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService' defined in ServletContext resource [/WEB-INF/service-config.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'userDao' of bean class [com.sxt.service.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?

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userAction' defined in ServletContext resource [/WEB-INF/web-config.xml]: Cannot resolve reference to bean 'userService' while setting bean property 'userService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService' defined in ServletContext resource [/WEB-INF/service-config.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'userDao' of bean class [com.sxt.service.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?


Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService' defined in ServletContext resource [/WEB-INF/service-config.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'userDao' of bean class [com.sxt.service.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?

Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'userDao' of bean class [com.sxt.service.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?

2016-9-6 16:42:53 org.apache.catalina.core.StandardContext loadOnStartup
严重: Servlet /spmvc01 threw load() exception
org.springframework.beans.NotWritablePropertyException: Invalid property 'userDao' of bean class [com.sxt.service.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?


 

 

解决办法:

看错误,从最底层看,最后一个cause by,因为如果最底层出错,上面的也会出错,因为代码是从最底层往上注入的,下面的错了,上面的也就错了,所以先看最底层的。

看到最底层,发现,UserService类中有无效的setter方法,查看UserService,发现里面的set方法确实有问题,忘记写参数了。

 

一般,get和set方法的生成,最好自动生成,因为自己写的话,容易出错。自动生成的办法: 在代码空白处右击-Source-Generate Getters and Setters,然后选择需要生成的方法即可。

posted on 2016-09-07 09:41  cyy_13  阅读(417)  评论(0编辑  收藏  举报