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的命名规范,所以,注入变量名必须首字母小写

    
    
    
    
    

    
    
        
            
        
        
            
        
    



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


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

 

你可能感兴趣的:(javase编程题)