<mvc:annotation-driven/> 和有什么区别?和 <context:annotation-config/>在 servlet 中? [英] What's the difference between <mvc:annotation-driven /> and <context:annotation-config /> in servlet?

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

问题描述

我正在从 Spring 2.5 迁移到 Spring 3.

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 中,我刚刚使用了 code> 标记在 application-context.xml 和调度程序 servlet 配置 XML 中声明,并带有要扫描的适当基本包.

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 配置中的 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 控制器的显式支持(即 @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:annotation-driven/&gt; 和有什么区别?和 &lt;context:annotation-config/&gt;在 servlet 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆