解决Bean property ** is not writable or has an invalid setter method

一笑奈何 提交于 2020-04-03 06:52:25

struts2+spring真让人纠结……

 

遇到了Bean property ** is not writable or has an invalid setter method这样的错误  正好找到个类似的解答

 

用SSH2框架,为某Action注入Bo时出现NotWritablePropertyException异常.当时是用同事已写好的名字cMsgbo.但启动tomcat时总抛出NotWritablePropertyException异常.详细异常信息如下:

Error creating bean with name '/count' defined in ServletContext resource [/WEB-INF/classes/kingtoonApplicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'cMsgbo' of bean class [com.kingtoon.count.struts.action.CountAction]: Bean property 'cMsgbo' is not writable or has an invalid setter method. Did you mean 'CMsgbo'?
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'cMsgbo' of bean class [com.kingtoon.count.struts.action.CountAction]: Bean property 'cMsgbo' is not writable or has an invalid setter method. Did you mean 'CMsgbo'?

这个错误信息最后问我是不是CMsgbo.于是乎我就随便换成一名字,比如comBo.然后再次启动Tomcat,服务器顺利启动.

总结:可能Spring会检查当前所起的名字是不是符合其规范以致可以认出是个什么东西来.如果起的名字不是很明确的话,那spring会给你一个异常,提示你换个名字吧,当前这个名字我认不出来.照她说的做就没问题了.

转自 http://hi.baidu.com/kingtoon_go/blog/item/8bdf6b38416f462796ddd878.html

 

我自己用的时候是在Action中实例化接口的时候拼写不一致导致的

public class BtnClickAction extends ActionSupport{
	IBtnClickSumService btnClickSumService;

 

之前写成

IBtnClickSumService btnClickService;

 

实例名少了几个字母就不行了,

擦……

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!