美文网首页Spring MVC 之 简单配置
@EnableWebMvc注解简单理解(未完成)

@EnableWebMvc注解简单理解(未完成)

作者: 巧哥儿 | 来源:发表于2017-08-07 15:51 被阅读1555次

@EnableWebMvc是使用Java 注解快捷配置Spring Webmvc的一个注解。在使用该注解后配置一个继承于WebMvcConfigurerAdapter的配置类即可配置好Spring Webmvc。

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

通过查看@EnableWebMvc的源码,可以发现该注解就是为了引入一个DelegatingWebMvcConfiguration Java 配置类。并翻看DelegatingWebMvcConfiguration的源码会发现该类似继承于WebMvcConfigurationSupport的类。其实不使用@EnableWebMvc注解也是可以实现配置Webmvc,只需要将配置类继承于WebMvcConfigurationSupport类即可。

viewControllerHandlerMapping.png beanNameHandlerMapping.png defaultServletHandlerMapping.png handlerExceptionResolver.png mvcViewResolver.png requestMappingHandlerAdapter.png requestMappingHandlerMapping.png resourceHandlerMapping.png

相关文章

网友评论

    本文标题:@EnableWebMvc注解简单理解(未完成)

    本文链接:https://www.haomeiwen.com/subject/urhalxtx.html