apache Digester:addSetNestedProperties 上出现意外的 NoSuchMethodException

发布于 2024-08-30 02:55:23 字数 790 浏览 10 评论 0原文

我在使用 Digester 时遇到问题,希望您能帮助我。我有以下 Bean:

public class MyEntry {
   private String entityID;

   public String getEntityID() { return this.entityID; }
   public void setEntityID(final String entityID) { this.entityID = entityID; }
}

以及以下 XML 结构:

<entries>
  <entry>
     <MyID>
        24309LAGH1
     </MyID>
  </entry>
</entries>

我使用 Digester API 的 addSetNestedProperties(…) 方法:

digester.addSetNestedProperties("entries/entry", "MyID", "entryID");

出现以下异常:

java.lang.NoSuchMethodException: Bean has no property named MyID

为什么 Digester 搜索名为“MyID”的属性?我根据消化器 API 将“entryID”指定为 bean 属性

谢谢:)

最好的问候 量子风暴

I have a problem using Digester and I hope you can help me. I have the following Bean:

public class MyEntry {
   private String entityID;

   public String getEntityID() { return this.entityID; }
   public void setEntityID(final String entityID) { this.entityID = entityID; }
}

And the following XML structure:

<entries>
  <entry>
     <MyID>
        24309LAGH1
     </MyID>
  </entry>
</entries>

I use the addSetNestedProperties(…) method of the digester API:

digester.addSetNestedProperties("entries/entry", "MyID", "entryID");

The following exception occurs:

java.lang.NoSuchMethodException: Bean has no property named MyID

Why is digester searching for a property named “MyID”? I specified “entryID” as bean property accorsing to the digester API

Thanks :)

Best regards
QStorm

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

玉环 2024-09-06 02:55:23

确保 getter 和 setter 的名称是您的属性“entityID”的大写或小写。可能您的 getter 名称是这样的 -->“getEntityID”尝试对此进行更改 -->“getentityID”

编辑< /strong>

抱歉,您需要检查的属性是 -->“MyID”

Make sure the name of getters and setters like are uppercase or lowercase of your property "entityID. Probably your getter name is like this --> "getEntityID" try to change for this --> "getentityID"

Edit

Sorry, the property you have to check is --> "MyID"

素手挽清风 2024-09-06 02:55:23

[原文]

你没有使用正确的规则来执行你的任务。

尝试使用这个:

digester.addBeanPropertySetter("entries/entry/MyID", "entityID");

提示:通过使用例如 BasicConfigurator.configure(); 在主程序中激活 log4j。输出可能非常有用。

[编辑]

如果你想使用 addSetNestedProperties:

public class MyEntry {
   private String entityID;

   public String getEntityID() { return this.entityID; }
   public void setEntityID(final String entityID) { this.entityID = entityID; }
}

和 for new Digester().parse(myFile);

digester.addObjectCreate("entries/entry", MyEntry.class);
digester.addSetNestedProperties("entries/entry", "MyID", "entityID");
//your propertyName was not the same as in your Bean Class Fields.

我认为你的例外是:

java.lang.NoSuchMethodException: Bean has no property named entryID

[original]

You do not use the correct rule to perform your task.

Try using this instead:

digester.addBeanPropertySetter("entries/entry/MyID", "entityID");

Tips: activate the log4j in your main by using for instance BasicConfigurator.configure();. The output can be very useful.

[edit]

If you want to use addSetNestedProperties:

public class MyEntry {
   private String entityID;

   public String getEntityID() { return this.entityID; }
   public void setEntityID(final String entityID) { this.entityID = entityID; }
}

and for new Digester().parse(myFile);

digester.addObjectCreate("entries/entry", MyEntry.class);
digester.addSetNestedProperties("entries/entry", "MyID", "entityID");
//your propertyName was not the same as in your Bean Class Fields.

and I presume that your Exception was:

java.lang.NoSuchMethodException: Bean has no property named entryID
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文