is not writable or has an invalid setter method错误的解决

is not writable or has an invalid setter method错误的解决2009-02-10 16:15因为Spring要求注入的成员变量要按照Sun的命名规范,所以,注入变量名必须首字母小写

    <!-- DAO -->
    <bean id="commonuserDao"
         class="cn.edu.ynu.sei.booki.persistence.dao.CommonUserDAO">
    </bean>
    <bean id="administratorDao"
         class="cn.edu.ynu.sei.booki.persistence.dao.AdministratorDAO">
    </bean>

    <!-- 用户门户 -->
    <bean id="userFacade"
         class="cn.edu.ynu.sei.booki.facade.UserFacade">
        <property name="commonuserDao">
            <ref bean="commonuserDao" />
        </property>
        <property name="administratorDao">
            <ref bean="administratorDao" />
        </property>
    </bean>



逻辑层的实现应该这样写:


public class UserFacade implements IUserFacade
{
     IUserDAO commonuserDao = new CommonUserDAO();

     IUserDAO administratorDao = new AdministratorDAO();

    /**
      * @return the commonuserDao
     */
    public IUserDAO getCommonuserDao()
     {
        return commonuserDao;
     }

    /**
      * @param administratorDao the administratorDao to set
     */
    public void setAdministratorDao(IUserDAO administratorDao)
     {
        this.administratorDao = administratorDao;
     }
   
     。。。。
}


注意,其中commonuserDao,即属性必须首字母小写,而且不能在中间混有大写,否则会提示不可写或者没有setter方法或不可写!

我的错误:

Invalid property 'smsHistoryDao' of bean class [cn.com.mt2.besttone.web.SMSHistoryAction]: Bean property 'smsHistoryDao' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

Unable to instantiate Action, smsHistoryAction, defined for 'inputQry' in namespace '/smsRcrd'Error creating bean with name 'smsHistoryAction' defined in file [E:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\haibaioam\WEB-INF\classes\spring\spring-actionContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'smsHistoryDao' of bean class [cn.com.mt2.besttone.web.SMSHistoryAction]: Bean property 'smsHistoryDao' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
javax.servlet.ServletException: Unable to instantiate Action, smsHistoryAction, defined for 'inputQry' in namespace '/smsRcrd'Error creating bean with name 'smsHistoryAction' defined in file [E:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\haibaioam\WEB-INF\classes\spring\spring-actionContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'smsHistoryDao' of bean class [cn.com.mt2.besttone.web.SMSHistoryAction]: Bean property 'smsHistoryDao' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?


原因:

定义为SMSHistoryDaoImpl smsRcrdQryDAO;

public SMSHistoryDaoImpl getSmsRcrdQryDAO() {
        return smsRcrdQryDAO;
    }

    public void setSmsRcrdQryDAO(SMSHistoryDaoImpl smsRcrdQryDAO) {
        this.smsRcrdQryDAO = smsRcrdQryDAO;
    }

应该改为:

SMSHistoryDaoImpl smsHistoryDao; 
public SMSHistoryDaoImpl getSmsHistoryDao() {
        return smsHistoryDao;
    }

    public void setSmsHistoryDao(SMSHistoryDaoImpl smsHistoryDao) {
        this.smsHistoryDao= smsHistoryDao;
    }

因为在配置文件中部署时,bean 的id是smsHistoryDao。
 


我也遇到上面的这种错误,主要原因是因为在把类定义成有下划线的变量,所以为了尽量不出现错误就不定义有下划线的类如: People_Child

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值