I have taken some of the useful comment from people..we can ..consider the points ..
There are benefits and drawbacks to using both XML and annotation based Spring configuration files. However, it doesn't have to be an 'either-or' type of decision.
There is a wider issue here, that of XML vs Annotation If your object model is only ever going to persisted in one way, then inlined meta-data (i.e. annotations) are more compact and readable.
If, however, your object model was reused in different applications in such a way that each application wanted to persist the model in different ways, then externalising the meta-data (i.e. XML descriptors) becomes more appropriate.
Neither one is better, and so both are supported, although annotations are more fashionable. More mature APIs like native Hibernate offer both, because it's known that neither one is enough.
--------------------------------------------------------------------------------------------------------------
Basically, there are pros and cons to all forms of configuration. Annotations, xml or Java Based Configuration. All the pros and cons are 100% valid. The main goal them becomes consistency. Making sure everyone on your project follows the same rules.
It is also NOT a question of either or, which one over the other. Because you can use any combination of configuration options in your application. One or all three combined. You just have to make your rules and stick to them
So my personal opinion is. Remember this is all my opinion and not fact.
1) Annotations over all other because I can configure and code much faster
2) Java Based configuration for those beans I can't annotate (They aren't my classes so I don't have the source to add an Annotation)
3) xml with what is left, or I need it complete externalized outside the package of my classes and I don't want to recompile and repackage. (Extremely rare, like it has never happened to me yet that I needed this)
2) Java Based configuration for those beans I can't annotate (They aren't my classes so I don't have the source to add an Annotation)
3) xml with what is left, or I need it complete externalized outside the package of my classes and I don't want to recompile and repackage. (Extremely rare, like it has never happened to me yet that I needed this)
--------------------------------------------------------------------------------------------------------------
First of all we use annotations for many more things, than just configuration.
Now: Some adventages of using annotations for configuration
Readability. For example in JPA configuration its much more cleaner to declare new entities by Annotations instead of hbm.xml files. These things change only in development stage so there is no problem with recompiling code. When You use xml files You have to often open both- entity and hbm file to make changes.. That can cause some erros.
Flexibility. In XML files you have to write all configs in "only one proper way". It is adventage and disadventage at the same time.
Length. XML-based configs are often very long (like pom's, or hbm's). Annotations are much simplier to use
No comments:
Post a Comment