本文介绍了< mvc:注解驱动的/>有什么区别?和< context:annotation-config/>在servlet中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从Spring 2.5迁移到Spring3.

I am migrating from Spring 2.5 to Spring 3.

他们引入了<mvc:annotation-driven />,它具有一些黑魔法.只能在servlet配置文件中声明它.

They have introduced <mvc:annotation-driven /> which does some black magic. This is expected to be declared in servlet configuration file only.

在Spring 2.5中,我只使用了在application-context.xml和调度程序servlet配置XML中声明的<context:annotation-config /><context:component-scan base='...'/>标记以及要扫描的基本包.

In Spring 2.5 I have just used <context:annotation-config /> and <context:component-scan base='...'/> tags declared both in application-context.xml and dispatcher servlet configuration XML with appropriate base packages to scan.

所以我想知道servlet config中mvc:annotation-drivencontext:annotation-config标记之间的区别是什么,我可以在Spring 3的配置文件中消除什么?

So I wonder what is the difference between mvc:annotation-driven and context:annotation-config tags in servlet config and what can I eliminate in Spring 3 config files?

推荐答案

<context:annotation-config>声明支持常规注释,例如@Required@Autowired@PostConstruct等.

<context:annotation-config> declares support for general annotations such as @Required, @Autowired, @PostConstruct, and so on.

<mvc:annotation-driven />声明显式支持注释驱动的MVC控制器(即@RequestMapping@Controller,尽管对默认行为的支持),并通过@Valid和消息正文添加对声明式验证的支持与@RequestBody/ResponseBody一起编组.

<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.

这篇关于&lt; mvc:注解驱动的/&gt;有什么区别?和&lt; context:annotation-config/&gt;在servlet中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 04:36