我们在SSH架构中写代码最容易出先的问题之一便是:
org.apache.jasper.JasperException: Error creating bean with name 'indexall' defined in file [E:/eclipse/Tomcat 5.5/webapps/fc/WEB-INF/beans.xml ]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'newsdao' of bean class [org.fc.classes.indexall]: Bean property 'newsdao' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter? |
这是一个很头痛的问题,基本解决方法有以下两种:
1,如上面提示在定义的ACTION方法里没写GET,SET方法或者是方法写的不规范
解决方法:
按如下编写看看能否解决.
Beasn.xml文件部分 //此文件是SPRING的配置文件
//
注册
indexall
这个
ACTION
<
bean
id
=
"indexall"
class
=
"org.fc.classes.indexall"
>
<
property
name
=
"
newsdao
"
>
//newsdao
为此
ACTION
调用的
DAO
文件
<
ref
local
=
"
newsdao
"
/>
</
property
>
</
bean
>
//
注册
newsdao
<
bean
id
=
"
newsdao
"
class
=
"org.fc.dao.base.Newsdao"
>
<
property
name
=
"sessionFactory"
>
<
ref
local
=
"sessionFactory"
/>
</
property
>
</
bean
>
//
最后必须在
userDAOProxy
中注册
<
bean
id
=
"userDAOProxy"
*********************************************
<
property
name
=
"target"
>
<
list
>
<
ref
local
=
"registerdao"
/>
<
ref
local
=
"
newsdao
"
/>
</
list
>
</
property
>
*********************************************
</
bean
>
Indexall
这个
ACTION
文件部分必须定义
newsdao
的
GET
,
SET
方法如下
private Newsdao
newsdao
;
public Newsdao getnewsdao(){
return newsdao;
}
public void setnewsdao(Newsdao newsdao){
this.newsdao=newsdao;
}
请大家注意下划线的变量,相同颜色的名字必须一致,不可有大小写错误!
|
2. TOMCAT版本的问题.本人一次用TOMCAT5.0编写,出现了上面的问题,结果是怎么都解决不了,后来换成了TOMCAT5.5.就一点问题都没有了,所以第一种办法解决不了的请用此法看看,换个TOMCAT版本也许能解决问题,不过只对用5.0编写出问题有效哦.