mvc:annotation-driven is a tag added in Spring 3.0 which does the following:
- Configures the Spring 3 Type ConversionService (alternative to PropertyEditors)
- Adds support for formatting Number fields with @NumberFormat
- Adds support for formatting Date, Calendar, and Joda Time fields with @DateTimeFormat, if Joda Time is on the classpath
- Adds support for validating @Controller inputs with @Valid, if a JSR-303 Provider is on the classpath
- Adds support for support for reading and writing XML, if JAXB is on the classpath (HTTP message conversion with @RequestBody/@ResponseBody)
- Adds support for reading and writing JSON, if Jackson is o n the classpath (along the same lines as #5)
context:annotation-config Looks for annotations on beans in the same application context it is defined and declares support for all the general annotations like
@Autowired, @Resource, @Required, @PostConstruct etc
etc.
**
<mvc:annotation-driven />
declares explicit support for annotation-driven MVC controllers (i.e. @RequestMapping, @Controller, although support for those is the default behaviour), as well as adding support for declarative validation via @Valid and message body marshalling with @RequestBody/ResponseBody.
个人理解就是,mvc:annotation-driven,是给spring-mvc增添了额外可用的注解,如@responseBody
等,并且显示声明了基础注解,如@RequestMapping
等(虽然这些注解是默认的)