Spring Framework: what is the purpose of

前端 未结 1 1414
耶瑟儿~
耶瑟儿~ 2020-12-17 05:47

I\'m relatively new to Spring and I\'m a little confused about the tag.

After going through the documentation and looking around different posts it seems like the

相关标签:
1条回答
  • 2020-12-17 06:29

    The support for @Controller and @RequestMapping is provided by Spring by default. However, by enabling mvc:annotation-driven you get support for processing the requests that are mapped to annotated controller methods, such as declarative validation, formatting and conversion service. An excerpt from spring's blog that introduced the new config features

    It applies sensible defaults based on what is present in your classpath. Such defaults include:

    • Using the Spring 3 Type ConversionService as a simpler and more robust alternative to JavaBeans PropertyEditors

    • Support for formatting Number fields with @NumberFormat

    • Support for formatting Date, Calendar, and Joda Time fields with @DateTimeFormat, if Joda Time is on the classpath
    • Support for validating @Controller inputs with @Valid, if a JSR-303 Provider is on the classpath
    • Support for reading and writing XML, if JAXB is on the classpath
    • Support for reading and writing JSON, if Jackson is on the classpath

    Another related usefull blog post

    If this tag is not added to the XML, then you will have to manually define the beans for components like HandlerAdapter, HandlerMapping, Binding Initializer, Request Message converters, etc. This tag helps registering the following components.

    • DefaultAnnotationHandlerMapping - This is a HandlerMapping implementation which maps the HTTP requests to the handler methods defined using the @RequestMapping annotation.
    • AnnotationMethodHandlerAdapter - It is responsible for scanning the controllers to identify methods (and parameters) annotated with @MVC annotations. It scans and caches handler methods annotated with @RequestMapping. Also handles the @RequestParam, @ModelAttribute, @SessionAttributes and @InitBinder annotations.
    • ConfigurableWebBindingInitializer - The initializer for the Web Data Binder. Helps in declaratively configuring the Web Binder with validators, conversion services, property editors, etc.
    • LocalValidatorFactoryBean - Implements the validator interface and enables JSR303 validation. This is injected into ConfigurableWebBindingInitializer.
    • FormattingConversionServiceFactoryBean - A conversion factory that returns conversion services for basic objects like date and numbers. This factory is again injected into ConfigurableWebBindingInitializer.
    • Support for Message Converters

    Finally a more formal definition in the official docs

    0 讨论(0)
提交回复
热议问题