At the moment for configuring Hibernate, Sprint, etc. You can use both XML configs and annotations. Most likely ask "What is better?" meaninglessly, so as not to breed holivar, so I ask the following:

What method do you use and why? What are the advantages and disadvantages of these methods?

So far, after reading a couple of arguments, I tend to annotations.



    7 answers 7

    I would "spread" the options like this:

    1. If you want a quick "fake" without non-standard distortions, then naturally annotations
    2. If there are a lot of non-standard chips in the project, then it is better to leave the annotations
    • one
      What does "non-standard chips" mean? - delphist007
    • one
      So all the same, those 2 people who zaplyusovali, explain to me what kind of "non-standard" chips can be made on xml? - delphist007

    But I'm still leaning towards XML. The most important thing for me (as with WEB programming) is "meat separately, bones separately." Those. It is more convenient when the styles are written in a separate file - the main code is not cluttered up, and it is easier to correct.

    Same with hibernate. You do not need to open the file with both sets and hets to change, say, the name of the table. You open .xml and rule there.

    Yes, and xml universal markup standard.

    • then we conclude, it all depends on the project and the developer. annotations take the speed of development, hml - the convenience of structuring. - Gorets

    @ delphist007 , try to change the mapping data without having the source, the most obvious plus is xml. And yes, because annotations are closer to jvm - then there is no need to read and parse external files -> performance gain (although whom I cheat, it’s almost imperceptible there, if at all)

      When using XML you do not need to recompile.

      • one
        Not a big deal when using Java, especially with incremental builds. - AlexeyM
      • one
        But, the war file will have to be rebuilt. - delphist007

      I read somewhere that it is better to use annotations. If I’m not mistaken, in cases if the annotation needs to be changed, but I don’t want to recompile the project, we create xml. Annotation in this case is ignored. But porridge can not be avoided :)

      • That's just the point, everyone writes what is best, but no one explains why. And the word just does not want to believe, I used to get sound answers. - delphist007
      • blog.codecentric.de/en/2012/07/… read right here - Anton Feoktistov

      Long live annotations!

      A more simple and understandable way to work with the spring is not difficult to even imagine.

      First, using annotations, you remove the problem of huge xml files. Secondly, you make the code more holistic, for example, in the controller, it is immediately clear that the method is jammed onto a specific request, etc. And so once again. Long live annotations!

        I use XML because I am just starting to work with Spring and have not yet come to the conclusion that it is necessary to reduce the size of the configuration file.

        • one
          @SashaOmelchenko and say that the answer did not even read :) - D-side
        • @ D-side why, read. it only seemed to me that most of it was a comment) - Sasha Omelchenko