java.lang.NoSuchMethodException:Bean没有名为的属性

时间:2013-09-13 11:00:16

标签: java apache-commons-digester

我的XML和Bean与属性“CostCenter”完全匹配,但仍然存在这个问题。请帮助解决这个问题。

例外:

Sep 13, 2013 4:25:23 PM org.apache.commons.digester3.Digester endElement
SEVERE: End event threw exception
java.lang.NoSuchMethodException: Bean has no property named CostCenter
    at org.apache.commons.digester3.BeanPropertySetterRule.end(BeanPropertySetterRule.java:206)
    at org.apache.commons.digester3.Digester.endElement(Digester.java:1097)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    at org.apache.commons.digester3.Digester.parse(Digester.java:1588)
    at org.apache.commons.digester3.Digester.parse(Digester.java:1557)
    at ecnet.yes.po.digester.DigestPO.digest(DigestPO.java:80)
    at ecnet.yes.po.digester.DigestPO.main(DigestPO.java:16)
Sep 13, 2013 4:25:23 PM org.apache.commons.digester3.Digester parse
SEVERE: An error occurred while parsing XML from 'file:/D:/workspace/Digester/src/ecnet/yes/po/digester/YES_PO.xml', see nested exceptions

DigestPO.java

    Digester digester = new Digester();
    //Push the current object onto the stack
    digester.push(this);
    digester.addSetProperties("ECnetPO");
    //Creates a new instance of the YESBarePO class
    digester.addObjectCreate("ECnetPO/Header", YESBarePO.class );

    //Uses setName method of the YESBarePO instance
    //Uses tag name as the property name
    digester.addBeanPropertySetter("ECnetPO/Header/PONumber","PONumber");
    digester.addBeanPropertySetter("ECnetPO/Header/CostCenter","CostCenter");

xml:

<ECnetPO>
    <Header>
        <PONumber>PONUMB0116</PONumber>
                <CostCenter>Cost Center 20</CostCenter>
        </Header>

    <Header>
        <PONumber>PONUMB0116</PONumber>
                <CostCenter>Cost Center 20</CostCenter>
        </Header>
</ECnetPO>

YESBarePO.java

private String  PONumber;
private String  CostCenter;
public String getPONumber()
{
    return PONumber;
}


public void setPONumber(String pONumber)
{
    PONumber = pONumber;
}
public String getCostCenter()
{
    return CostCenter;
}


public void setCostCenter(String costCenter)
{
    CostCenter = costCenter;
}

1 个答案:

答案 0 :(得分:2)

只是一个猜测,但如果您将实例变量YESBarePO.CostCenter重命名为YESBarePO.costCenter,它会有所作为吗?例如,与.NET不同,标准的Java习惯是使用lowerCamelCase作为实例变量,我的经验表明,一些bean映射器需要遵守此约定才能工作。