EnableWebMvc value for annotation

I am reading javadoc about @EnableWebMvc .

But I do not understand what this annotation means?

Can you make this clear?

+43
java spring spring-mvc annotations
Oct 10 '13 at 8:57
source share
3 answers

When you use Java code (as opposed to XML) to customize your Spring application, @EnableWebMvc used to enable Spring MVC. If you are not already familiar with Spring support for Java configuration, this is a good place to run .

@EnableWebMvc equivalent to <mvc:annotation-driven /> in XML. It allows you to support @Controller annotated classes that use @RequestMapping to map incoming requests to a specific method. You can read detailed information about what it configures by default, and how to configure the configuration in the reference documentation .

+66
Oct 10 '13 at 9:30
source share

Welcome to the world of Spring. You need to understand before you know what the @EnableWebMVC annotation @EnableWebMVC .

Spring traditionally supports two types of configurations:

These annotations are essentially implemented as part of MVC Java Config Design .

Consider a simple class:

 @EnableWebMvc @Configuration public class WebConfig { } 

There are no base classes. No spring beans in sight .. Hmmm ..

Let's look a little further:

  • What does this really provide?

Well, to bore you a little, it provides a lot of things like:

and a few more.

Ahaha ... But your application works with it correctly. So where is the magic ...?

@EnableWebMVC <---- What behind this..?

This is behind her:

 @Retention(RetentionPolicy.RUNTIME) @Import(DelegatingWebMvcConfiguration.class) @Target(ElementType.TYPE) public @interface EnableWebMvc { } 

Look, now you would think how pointless to use @EnableWebMVC . Would you prefer:

You can read:

Hope this helps. :)

+29
10 Oct '13 at 11:10
source share

Adding this annotation to the @Configuration class imports the Spring MVC configuration from WebMvcConfigurationSupport

0
Dec 25 '17 at 15:19
source share



All Articles