Spring:Bean属性不可写或具有无效的setter方法

时间:2015-01-27 21:39:30

标签: java spring spring-mvc

我知道这个问题已被多次询问,但在我看来,一切都是正确的。我还从Eclipse中删除了我的代码,让IDE创建getter / setter但无济于事。

这是我在weblogic中的错误:

引起:org.springframework.beans.NotWritablePropertyException:bean类的无效属性'gpsDataAllStopsSql'[com.fedex.dire.webservices.direservice.dao.GPSDataDaoImpl]:Bean属性'gpsDataAllStopsSql'不可写或无效二传法。 setter的参数类型是否与getter的返回类型匹配?

这是我的Bean&在我的背景下的财产:

<bean id="dataDao" class="com.text.service.dao.DataDaoImpl" >
      <property name="dataSource" ref="dataSource" />
      <property name="gpsDataAllStopsSql">
          <value><![CDATA[SELECT A.XML_DATA,B.ADDR1,B.ADDR2,B.POSTALCODE  FROM GPS.EVENT_STAMP A LEFT OUTER JOIN DB.SCAN B ON  A.FAC_IORG_NBR=B.FACILITY AND A.SCANNER_DATE=B.SCANDATE AND A.SCANNER_ID=B.SCANNERID AND A.PD_START_TIME=B.PDSTART WHERE FAC_IORG_NBR = ?  AND SCANNER_DATE = CAST(? AS DATE) AND SCANNER_ID = ? AND PD_START_TIME = ?]]></value>
    </property> 
      <property name="gpsDataSql">
          <value><![CDATA[SELECT A.XML_DATA,A.STOP_NUMBER,B.ADDR1,B.ADDR2,B.POSTALCODE FROM GPS.EVENT_STAMP A LEFT OUTER JOIN DB.SCAN B ON  A.STOP_NUMBER=B.STOP# AND A.FAC_IORG_NBR=B.FACILITY AND A.SCANNER_DATE=B.SCANDATE AND A.SCANNER_ID=B.SCANNERID AND A.PD_START_TIME=B.PDSTART WHERE FAC_IORG_NBR = ?  AND SCANNER_DATE = CAST(? AS DATE) AND SCANNER_ID = ? AND PD_START_TIME = ? AND STOP_NUMBER = ?]]></value>
 </property> 
 </bean>

以下是我的DaoImpl中的getter和setter方法:

private static String gpsDataSql = null;

private static String gpsDataAllStopsSql = null;

public static String getGpsDataSql() {
    return gpsDataSql;
}

public static void setGpsDataSql(String gpsDataSql) {
    DataDaoImpl.gpsDataSql = gpsDataSql;
}

public static String getGpsDataAllStopsSql() {
    return gpsDataAllStopsSql;
}

public static void setGpsDataAllStopsSql(String gpsDataAllStopsSql) {
    DataDaoImpl.gpsDataAllStopsSql = gpsDataAllStopsSql;
}

我的眼睛是否有滑动的东西,或者它是我环境的另一个问题?

谢谢!

1 个答案:

答案 0 :(得分:1)

您在XML中声明的bean尝试设置DataDaoImpl类中存在的属性。为了使其正常工作,请删除静态成员并为您的课程尝试以下内容:

package com.text.service.dao;

public class DataDaoImpl extends SomeOtherDaoWhereDataSourceIsDefined {
    private String gpsDataAllStopsSql;
    private String gpsDataSql;

    public String getGpsDataAllStopsSql() {
        return gpsDataAllStopsSql;
    }

    public void setGpsDataAllStopsSql(String gpsDataAllStopsSql) {
        this.gpsDataAllStopsSql = gpsDataAllStopsSql;
    }

    public String getGpsDataSql() {
        return gpsDataSql;
    }

    public void setGpsDataSql(String gpsDataSql) {
        this.gpsDataSql = gpsDataSql;
    }
}

This article解释了静态与非静态成员的用法。