Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: annotation vs. xml

  1. #11
    Join Date
    Nov 2005
    Posts
    114

    Default

    Quote Originally Posted by zzkhan View Post
    I think viewnames for controllers (e.g. formView, successView and so on) come under configuration as well and for goods reasons, for instance if you need to reuse the logic in a given controller for presenting different views and the fact that you dont want to hardcode the flow of the application in your code.

    Specifying viewnames in spring config was done by convention before the introduction of Annotated controllers in 3.0 because the good old Abstract Controller classes sort of 'advised' us to do so along with some other stuff. However after the advent of Annotated controllers, a lot of the 'guiding principles' (some viewed these as constraints) are gone with the abstract controllers getting deprecated in 3.0.

    For people who despise XML configuration annotations is seen as the way to go to get to this utopia zero XML config controller configuration, and in getting to this the tendency is to hardcode things like viewnames in the controllers just to get away with not having it in configuration which I think is wrong as you are taking away the flexibility of your application just to save a handful of XML config.

    Any thoughts?
    I agree
    I tend to use annotations only to avoid the dependency of the mvc class itself. I still prefer the xml configuration since I find many places where a single controller class is configured differently for serving different cases. Furthermore this framework-independance allows me to have some base functionality classes that can be extended by my controllers no matter if they are SimpleForm or ParametrizableView style or whatever. Untill 2.5 I had to use some type of delegation pattern for these cases but no more...
    I still believe though that new Spring users should have a look at the javadocs of the -now deprecated- controllers (especially AbstractFormController) to have a basic idea of how things are handled under the covers

  2. #12
    Join Date
    Apr 2008
    Posts
    22

    Default

    Quote Originally Posted by Jabberz View Post
    Personally, I avoid annotations. In the purest of POJO designs, using an annotation couples that source file to the provider of the annotation. The config file approach, while perhaps being slightly more effort to maintain, preserves the POJO in that your source code has no direct coupling.
    I concur with this point. Despite many peoples adversion to xml config (or any external config) I find it better to decouple from code as much as possible with frameworks and true config type data. Now, annotations that are part of the base language structure I use including ones that allow injection of Spring items. In addition, having all your config / injection in one place allows for easy knowledge of where a bean is used.

    Another place where I often 'violate' this standard is in JUnit tests where I annotate injection more to save on test specific config. At least so far that has not been a 'bad' thing.

  3. #13
    Join Date
    Aug 2006
    Location
    Now Germany, previously Ukraine
    Posts
    1,546

    Default

    And annotations are especially convenient to configure beans of 3rd-party classes .

    Quote Originally Posted by darted View Post
    I concur with this point. Despite many peoples adversion to xml config (or any external config) I find it better to decouple from code as much as possible with frameworks and true config type data. Now, annotations that are part of the base language structure I use including ones that allow injection of Spring items. In addition, having all your config / injection in one place allows for easy knowledge of where a bean is used.

    Another place where I often 'violate' this standard is in JUnit tests where I annotate injection more to save on test specific config. At least so far that has not been a 'bad' thing.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •