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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28180528/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 13:08:38  来源:igfitidea点击:

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

javaspringspring-mvc

提问by Matthew Lancaster

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.

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

Here's my error in weblogic:

这是我在 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?

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

Here's my Bean & Property in my context:

这是我的 Bean & Property 在我的上下文中:

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

以下是我的 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;
}

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

有什么东西让我的眼睛滑过,还是我的环境有另一个问题?

Thanks!

谢谢!

采纳答案by wassgren

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

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

这篇文章解释了静态和非静态成员的用法。