Matthew Lancaster
Matthew Lancaster

Reputation: 519

Spring: Bean property is not writable or has an invalid setter method

I know this question has been asked multiple times but to my eyes everything is correct. I've also deleted my code from Eclipse and let the IDE create the getters/setters but no avail.

Here's my error in weblogic:

Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'gpsDataAllStopsSql' of bean class [com.fedex.dire.webservices.direservice.dao.GPSDataDaoImpl]: Bean property 'gpsDataAllStopsSql' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

Here's my Bean & Property in my context:

<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>

Here are the getter and setter methods in my DaoImpl:

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;
}

Is there something my eyes are gliding over or could it be another issue with my environment?

Thanks!

Upvotes: 1

Views: 21214

Answers (1)

wassgren
wassgren

Reputation: 19211

The bean you are declaring in the XML tries to set properties that exists on the DataDaoImpl class. For this to work properly, remove the static members and try the following for your class:

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 explains the usage of static vs non static members.

Upvotes: 1

Related Questions