File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Spring and the fly likes <mvc:annotation-driven/> Vs <context:annotation-config/> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "<mvc:annotation-driven/> Vs <context:annotation-config/>" Watch "<mvc:annotation-driven/> Vs <context:annotation-config/>" New topic

<mvc:annotation-driven/> Vs <context:annotation-config/>

Rakesh Basani
Ranch Hand

Joined: Jun 04, 2012
Posts: 38
Hi friends..

According to my spring mvc knowledge <mvc:annotation-driven/> and <context:annotation-config/> these both are used to detect the annotations like @Controller,@ResponseBody,..

could anyone tell me the exact difference between these two tags in dispatcher-servlet.xml

Thanks in advance.
Bill Gorder

Joined: Mar 07, 2010
Posts: 1682

<mvc:annotation-driven/> is a tag added in Spring 3.0 which does the following:

1. Configures the Spring 3 Type ConversionService (alternative to PropertyEditors)
2. Adds support for formatting Number fields with @NumberFormat
3. Adds support for formatting Date, Calendar, and Joda Time fields with @DateTimeFormat, if Joda Time is on the classpath
4. Adds support for validating @Controller inputs with @Valid, if a JSR-303 Provider is on the classpath
5. Adds support for support for reading and writing XML, if JAXB is on the classpath (HTTP message conversion with @RequestBody/@ResponseBody)
6. Adds support for reading and writing JSON, if Jackson is o n the classpath (along the same lines as #5)

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.

[How To Ask Questions][Read before you PM me]
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Also to point out.

<context:annotation-config> does NOT search for @Component, @Controller, etc.

<context:component-scan> DOES search for those @Component annotations, as well as the annotations that <context:annotation-config/> does.


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Rakesh Basani
Ranch Hand

Joined: Jun 04, 2012
Posts: 38
thank you very much for your replies guys..
jQuery in Action, 3rd edition
subject: <mvc:annotation-driven/> Vs <context:annotation-config/>
It's not a secret anymore!