java annotations: library to override annotations with xml files

时间秒杀一切 提交于 2019-12-03 16:31:54

问题


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?


回答1:


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



回答2:


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




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/1470368/java-annotations-library-to-override-annotations-with-xml-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!