• 缺setter异常


    严重: 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,然后选择需要生成的方法即可。

  • 相关阅读:
    【CH 5501】环路运输【DP】【单调队列】
    【CH 5501】环路运输【DP】【单调队列】
    【POJ 1456】Supermarket【并查集】
    【POJ 1456】Supermarket【并查集】
    【POJ 1456】Supermarket【并查集】
    【POJ 2411】Mondriaan's Dream【DP】
    数据结构实验之二叉树二:遍历二叉树
    数据结构实验之二叉树二:遍历二叉树
    36 静态数据成员与静态成员函数
    36 静态数据成员与静态成员函数
  • 原文地址:https://www.cnblogs.com/cyy-13/p/5848254.html
Copyright © 2020-2023  润新知