有哪些优点/注释(非编译器)的缺点相比,XML配置文件 [英] What are the Pros/Cons of Annotations (non-compiler) compared to xml config files
问题描述
当我看着像Hibernate,JPA或Spring的Java框架,我通常让我的配置通过XML文件或者直接把批注在我的课的可能性。
When I look at Java frameworks like Hibernate, JPA, or Spring, I usually have the possibility to make my configuration via an xml-file or put annotations directly in my classes.
我cosistently问自己,我应该去什么样的方式。
I am cosistently asking myself what way should I go.
当我使用注解,我有类和它的配置在一起,但与XML,我得到我的系统的一个更大的图片,因为我可以看到所有类的配置。
When I use annotations, I have the class and its configuration together but with an xml I get a bigger picture of my system because I can see all class-configurations.
注解也被编译在某些方面我想,这应该是比解析XML更快,但另一方面,如果我想改变我的配置我不得不重新编译它,而不是只是改变了xml文件(这可能成为客户端的生产环境)更加得心应手。
Annotations also get compiled in some way I guess and it should be quicker than parsing the xml, but on the other hand, if I want to change my configuration I have to recompile it instead of just changing the xml file (which might become even more handy for production environments on customer side).
所以,看我点的时候,我倾向于去了XML的方式。但在平时使用注解。论坛或教程看时
So, when looking at my points, I tend to go the xml-way. But when looking at forums or tutorials usually annotations are used.
你有什么利弊?
推荐答案
一个好的经验法则:任何你可以看到自己想要更改,恕不一个完整的重新部署(例如,调整性能参数)应该去的东西软配置如XML文件。什么是现实永远不会改变 - 或者只是在排序,在那里你会也不得不改变code的情况 - 可以合理地在注释
A good rule of thumb: anything you can see yourself wanting to change without a full redeploy (e.g. tweaking performance parameters) should really go in something "soft-configurable" such as an XML file. Anything which is never realistically going to change - or only in the sort of situation where you'll be having to change the code anyway - can reasonably be in an annotation.
忽略的注释和XML之间的性能差异的任何想法 - 除非你的配置是绝对的大规模的区别将是微不足道的。
Ignore any ideas of performance differences between annotations and XML - unless your configuration is absolutely massive the difference will be insignificant.
这是灵活性和可读性集中注意力。
Concentrate on flexibility and readability.
这篇关于有哪些优点/注释(非编译器)的缺点相比,XML配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!