我的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;
}
最佳答案
只是一个猜测,但是如果您将实例变量YESBarePO.CostCenter
重命名为YESBarePO.costCenter
,会有所不同吗?例如,与.NET不同,标准Java习惯用法是将lowerCamelCase用作实例变量,而我的经验表明,某些bean映射器需要遵守此约定才能起作用。