我一直在研究使用mvc:annotation-driven标签时我们有哪些额外的功能,我很难消化结果,特别是在@Controller注释方面.我知道这与this question非常相似,但请听我说.
The basic purpose of the @Controller annotation is to act as a stereotype for the annotated class, indicating its role. The dispatcher will scan such annotated classes for mapped methods, detecting @RequestMapping annotations (see the next section).
然后,文档继续显示上下文:component-scan标记提供此支持.所以这一切都很好,但后来我看着mvc:annotation-driven给了我们,前面提到的stackoverflow question提供了以下答案
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 declrative validation via @Valid and message body marshalling with @RequestBody/ResponseBody.
这对我来说似乎有点多余.也许我得不到这种明确的支持.再次,回顾官方的Spring documentation,我们得到以下内容
[mvc:annotation-driven] registers the DefaultAnnotationHandlerMapping and AnnotationMethodHandlerAdapter beans that are required for Spring MVC to dispatch requests to @Controllers.
这听起来与我从文档中提供的最后一个例子非常相似.如果任何人都可以提供一些关于我们如何使用@Controller注释只使用上下文:component-scan标签,一些限制是什么,那么我们在添加mvc:annotation-driven时获得的附加功能的示例标签,我认为这将非常有帮助.在此先感谢任何支持.