java 注释:用 xml 文件覆盖注释的库

发布于 2024-08-06 12:18:20 字数 230 浏览 4 评论 0原文

Java 有注释,这很好。然而,一些开发人员认为最好使用 xml 文件用元数据注释代码 - 其他开发人员更喜欢注释,但会使用元数据覆盖源代码中的注释。

我正在编写一个使用注释的 Java 框架。问题是:是否有一种标准方法来定义和解析 xml 文件中的元数据。我认为这是每个使用注释的框架都可以受益的东西,但我似乎可以在互联网上找到类似的东西。

我必须自己进行 xml 解析/验证吗?或者有人已经做过类似的事情了吗?

Java has annotations and that is good. However, some developers feel that it is best to annotate code with metadata using xml files - others prefer annotations but would use metadata to override annotations in source code.

I am writing a Java framework that uses annotations. The question is: is there a standard way to define and parse metadata from xml files. I think this is something every framework that uses annotations could benefit from but I can seem to find something like this on the Internet.

Must I roll my own xml parsing/validation or has someone already done something like this?

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

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

发布评论

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

评论(4

却一份温柔 2024-08-13 12:18:20

没有标准的方法,但这里有一些 Java 框架可以做到这一点:

There is not a standard way, but here are some Java frameworks who does it:

  • JPA - check ejb-3_0-fr-spec-persistence.pdf
  • Spring Framework
  • TestNG - as written above, though I think it focuses to much on the annotation side rather than the actual configuration he tries to achieve
  • Seam Framework
大海や 2024-08-13 12:18:20

我编写了 Annox 库,它正是您所需要的。使用 Annox,您可以从 XML 读取任意注释。

I wrote the Annox library which does exactly what you need. With Annox you can read arbitrary annotations from XML.

萌吟 2024-08-13 12:18:20

这并不完全是您想要的,但是 backport175 项目 具有针对 Java 5 之前的 Java 版本的注释实现。

它具有您搜索的一些功能,它将读取自己的样式实现和“真实”注释(如果存在)。也许这可以作为构建更通用框架的起点。

It's not exactly what you want, but the backport175 project has an implementation of annotations for Java versions before Java 5.

It has some of the functionality you search in that it will read both its own style implementations and "real" annotations if they are present. Maybe this can be used as a starting point to build a more general framework.

断桥再见 2024-08-13 12:18:20

使用 JAXB http://java.sun.com/developer/technicalArticles/WebServices/jaxb /
您将为元数据文件编写 xsd,生成可以帮助您解析 xml 文件的 JAXB 类。

Use JAXB http://java.sun.com/developer/technicalArticles/WebServices/jaxb/
You would write the xsd for your metadata file, generate JAXB classes that can help you parse the xml files.

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