Announcement Announcement Module
Collapse
No announcement yet.
mvc:annotation-driven vs defaults Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • mvc:annotation-driven vs defaults

    Hello,

    in the spring 3 core course handout i read the following:

    "
    HTML Code:
    <mvc:annotation-driven/>
    Registers HandlerMapping and ~Adapter for @MVC.

    - Means you loose the other default mappings and adapters!
    "

    What exactly am i loosing?

    As I understand it, I can still use my annotations, and I even can use the stateless conversion service, REST and JSR-303 support.

    Which defaults are no longer active when i use this tag?

  • #2
    The defaults of the dispatcher servlet are almost the same as the defaults of mvc:annotation-driven... There is a bit more setting up done for you... JSR-303 is detected (this isn't by the dispatcher servlet you need configuration for that), some HttpMessageConverters, depending on the included jars are pre-configured and instead of the DefaultAnnotationHandlerMapping (and accompaning HandlerAdapter) the RequestMappingHandlerMapping/-HandlerAdapter is registered, which is more powerful and flexible.

    But if you have the course handout you probably want to ask your trainer

    Comment


    • #3
      I even got certified,that's why its still bothering me
      I agree that more powerfull things get activated. But what do i really loose?
      I found a properties file next to the DispatcherServlet in the jar file (in the same package as the DispatcherServlet).
      Are these the settings i'm loosing?

      Comment


      • #4
        Well yes and no... I suggest take a look at the properties file and the WebMvcConfigurationSupport class (which is what registers the mvc:annotation-driven beans).

        Comment


        • #5
          Hello,

          this WebMvcConfigurationSupport class is a 3.1 spring class, not 3.0.
          According to this link (watch the since attribute):

          http://static.springsource.org/sprin...onSupport.html

          I think the training docs are expressing 'loose' a bit too strong. From what i can see, you don't 'loose' anything. You get the same as the defaults but with some additional configuration.

          These are the defaults i found in the DispatcherServlet.properties:


          Code:
          # Default implementation classes for DispatcherServlet's strategy interfaces.
          # Used as fallback when no matching beans are found in the DispatcherServlet context.
          # Not meant to be customized by application developers.
          
          org.springframework.web.servlet.LocaleResolver=org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver
          
          org.springframework.web.servlet.ThemeResolver=org.springframework.web.servlet.theme.FixedThemeResolver
          
          org.springframework.web.servlet.HandlerMapping=org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,\
          	org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping
          
          org.springframework.web.servlet.HandlerAdapter=org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,\
          	org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,\
          	org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter
          
          org.springframework.web.servlet.HandlerExceptionResolver=org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver,\
          	org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver,\
          	org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver
          
          org.springframework.web.servlet.RequestToViewNameTranslator=org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator
          
          org.springframework.web.servlet.ViewResolver=org.springframework.web.servlet.view.InternalResourceViewResolver

          Comment


          • #6
            In Spring 3.1 both <mvc:annotation-driven> and the MVC Java config make sure you get all the extra DispatcherServlet.properties defaults so you don't lose anything really any more.

            Comment

            Working...
            X