Results 1 to 6 of 6

Thread: mvc:annotation-driven vs defaults

  1. #1

    Question 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. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    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
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3

    Default

    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?

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    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).
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5

    Default

    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

  6. #6
    Join Date
    Aug 2006
    Location
    Brooklyn
    Posts
    556

    Default

    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.

Tags for this Thread

Posting Permissions

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