Announcement Announcement Module
Collapse
No announcement yet.
Performance | Spring version 2.5 + Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Performance | Spring version 2.5 +

    Hi,

    I would like to know what added advantage does Spring provide when it comes up with annotations like @Controller? Would the framework not have to search for all such files in the application to scan for the request mapping?

    Rather the previous version seemed to be better wherein for the request mapping there was a specific bean assigned to it.

    Also there were predefined lifecycle methods like handlRequest etc which returned the ModelAndView object, i see that now we can define a method and return String?

    Using the above, can this be configured in the xml? i.e. can i say to the container that a particular method needs to be called for a particular request mapping using xml config?

    Can someone please help understand the advantages of Spring 2.5 + over the previous versions?

    -Hetal

  • #2
    Hi,

    Even i have similar kind of questions as mentioned my Hetal

    Annotations have made our lifes difficult as it was easier maintaining configurations in XML file.

    Like it was better having controllers in the XML file rather than annotating it .The use of @Bean in a Java file rather than declaring a simple bean definition in XML file is somewhat we could avoid of.

    Annotations are nothing but using Reflection of Java API and i somehow feel that using more and more reflection in Java will hamper the performance.

    Can anyone suggest on why the new releases are emphasisng more on annotations.

    -kartik

    Comment


    • #3
      Can anyone suggest on why the new releases are emphasisng more on annotations.
      Because YOU want it, it is request by the user hence it is there. However it doesn't mean xml is deprecated (I tend to use xml in conjunction with annotations a lot) everything you can do with annotations you can do (sometimes easier/more powerful) with xml.

      Annotations don't really imply the use of Reflections, it is more of specifing metadata (like @Transactional). Regarding the performance at runtime there is no performance hit, the only 'performance hit' is during startup. After that annotations aren't used anymore. They are only used to specify configuration, which is a one time thing.

      So @Controllers etc. are detected during startup, however if you want specify them yourself in xml. Using annotations doesn't mean you cannot use xml anymore. Heck if you want you can mix configuration in properties files, xml files, annotations and java. It is just configuration, scanned once not each time.

      Regarding @Controller (and other mvc stuff) they are more powerful and easier to use then the old still rigid controllers. (I had to battle with them way to much) Especially in conjunction with @PathVariable. They allow for much easier methods, thinner methods and easier to test methods, instead of trying to shoehorn you (or your app) in a certain lifecycle.

      Using the above, can this be configured in the xml? i.e. can i say to the container that a particular method needs to be called for a particular request mapping using xml config?
      No. You can use xml to tell use this controller for this url and use @RequestMappings for the more fine grained mapping.
      Last edited by Marten Deinum; Jan 27th, 2010, 08:09 AM.

      Comment


      • #4
        Marten, Thanks for the reply.

        During start up itself, if i have my application designed in a way that i have multiple Controllers and if annotations are used, the container would have to scan all these files and read through the RequestMapping right?

        Whereas in the traditional vversions it was directly mapped and given to the container. So i was just thinking of what could really have driven these changes.

        -Hetal

        Comment


        • #5
          All that information is scanned during startup, so it is only once, after that the DefaultAnnotationHandlerMapping knows which method to invoke on which controller for which url.

          Also if you would use a MultiActionController you would exactly have the same behavior but it would be part of the Controller instead of the HandlerMapping. The MultiActionController would probably be slower then the @Controller one (although I don't have any proof to back that up) next to the fact that it is less powerful.

          Comment


          • #6
            Thanks

            I personally prefer the old traditional way of doing it since incase of maintainability and also distribution of work, it would be better to have the mappings in the xml rather than scanning the code throughout the application just to find out the metadata.

            May be only once i face some potential issues while working on the older versions, i will get to know more about the advantages of the new versions.

            Thanks for your replies

            Comment


            • #7
              I personally prefer the old traditional way of doing it since incase of maintainability and also distribution of work, it would be better to have the mappings in the xml rather than scanning the code throughout the application just to find out the metadata.
              Which is why I tend to use a combination of both, coarse grained url mappings mapped to @Controllers in xml, the fine grained mapping is then in your controller. The best of both worlds basically..

              Comment

              Working...
              X