SpringMVC源码之@EnableWebMvc注解工作原理

@EnableWebMvc注解工作原理篇

查看spring源码发现该注解没有设置任何方法,也就是一个标识注解,spring官方文档是这样介绍的:

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

简单的说就是通过该注解,将WebMvcConfigurationSupport这个Spring MVC核心类注册到spring容器中。查看该类源码如下:

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

可以很清楚的看到,在注册该注解标示的类之前先注册DelegatingWebMvcConfiguration类。
注意:@EnableWebMvc必须配合@Configuration注解一起使用

你可能感兴趣的:(Spring,Spring源码讲解)