Announcement Announcement Module
Collapse
No announcement yet.
Pro&Con of the three spring configurations Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Pro&Con of the three spring configurations

    I have been working with spring framework for many many years. However I have been used exclusively xml based configurations (i.e. spring-webapp.xml..etc). I have found the xml base configuration simple and easier to understand.

    1. Traditional XML based metadata
    2. Annotation-based configuration
    3. Java-Based configuration


    I always see the spring 2.5 annotation-based configuration as a nice add-on feature for supplementing the core xml based configuration and never take it seriously. With the introduction of spring 3.0 java-based configuration, I have a couple of questions regarding to these approaches.

    1. Am I correct that both annotation-based and java-based are designed to be supplement for the core xml based configuration, but not as an replacement?

    2. If the first question is "yes", then the common practice would be a hybrid of these three methods, am I correct?

    3. What's the PRO(s) and CON(s) of the annotation-based and java based configurations?

    4. Any scenario(s)/situation(s) that annotation-based or java based would be better options than the old xml-based configuration?

    Thanks.

  • #2
    Annotations vs XML

    Hello,

    I've worked on projects using both XML configured beans and annotation driven beans. I find annotation configured applications to be much faster to develop. I found myself combing through a lot of XML during development. @Autowired is just so easy to add if you need a service or dao injected into your bean. Also I find it nice to control transactions with the @Transactional annotations. Also I believe that @Repository beans will automatically wrap exceptions thrown into Spring based exceptions. Just another neat feature of annotations that you would probably have to account for yourself.

    Thanks

    Comment


    • #3
      Hello

      Just don't panic when you read somewhere that "XML configuration is sooo 2004" or hear terms like "XML hell".

      I've worked with many Spring/JavaEE projects - just use such configuration method which best suits your needs. Annotations are great for Spring MVC controllers (and in Spring 3.0 they're covering all aspects of web app - from rourting, through binding, validation to generating model for views).

      But XML configuration is still needed! How can you configure existing objects? Maybe I'm missing something but you can't do that in CDI (JSR-299) - and I don't think @Producer methods are good for that.

      So - use annotations for your business classes, controllers, daos, but configure datasources, sessionfactories, JPA managers in XML. You can choose proper XML configuration file at runtime/deployment/test - you can't do that with annotations.

      regards
      Grzegorz Grzybek

      Comment


      • #4
        Originally posted by Grzegorz Grzybek View Post

        I've worked with many Spring/JavaEE projects - just use such configuration method which best suits your needs. Annotations are great for Spring MVC controllers (and in Spring 3.0 they're covering all aspects of web app - from rourting, through binding, validation to generating model for views).
        Would you give me a number of suggestions of some useful annotations? So I don't want to miss out some real handy annotations.

        Thanks.

        Comment


        • #5
          Originally posted by Grzegorz Grzybek View Post
          Annotations are great for Spring MVC controllers (and in Spring 3.0 they're covering all aspects of web app - from rourting, through binding, ...).
          Interesting! I want to see some samples too.

          Comment


          • #6
            Originally posted by vw729 View Post
            Interesting! I want to see some samples too.
            Hi Senior Member vw729! I'm not sure you're sarcastic or not

            Anyway - everything's in http://static.springsource.org/sprin...ann-controller

            If "routing" is confusing, for me routing is defined with @RequestMapping annotations.

            In Spring 3 the annotation configuration is complete - thanks to @Valid (JSR303).

            Happy New Year
            Grzegorz Grzybek

            Comment

            Working...
            X