mvc:annotation-driven and context:annotation-config and context:component-scan

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

<context:annotation-config/>
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.

ALSO:

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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s