现在的位置: 首页 > 综合 > 正文

SSH架构易出现的问题之Error creating bean with name ‘*’ defined in file [*.xml]

2014年01月30日 ⁄ 综合 ⁄ 共 1558字 ⁄ 字号 评论关闭

 

我们在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文件部分必须定义newsdaoGETSET方法如下
 
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编写出问题有效哦.

 

抱歉!评论已关闭.