<mvc:annotation-driven />
会自动注册DefaultAnnotationHandlerMapping
与AnnotationMethodHandlerAdapter
两个bean,是spring MVC为@Controllers
分发请求所必须的。并提供了:数据绑定支持,@NumberFormatannotation
支持,@DateTimeFormat
支持,@Valid
支持,读写XML的支持(JAXB),读写JSON的支持(Jackson)。
<context:annotation-config>
declares support for general annotations such as @Required
,@Autowired
, @PostConstruct
, and so on.
<mvc:annotation-driven />
is actually rather pointless. It declares explicit support for annotation-driven MVC controllers (i.e.@RequestMapping
, @Controller
, etc), even though support for those is the default behaviour.
My advice is to always declare <context:annotation-config>
, but don't bother with <mvc:annotation-driven />
unless you want JSON support via Jackson.
网友评论