美文网首页
springboot(2.X)下webmvc配置方式

springboot(2.X)下webmvc配置方式

作者: 继李扶危 | 来源:发表于2020-02-20 14:47 被阅读0次

springboot在启动mvc时有三种方式:1、使用@EnableWebMvc注解,2、用WebMvcAutoConfiguration(在包org.springframework.boot.autoconfigure.web.servlet下)、3、继承WebMvcConfigurationSupport重写需要的函数。

使用第3种方法时第2中会失效,因为WebMvcAutoConfiguration上有注解@ConditionalOnMissingBean(WebMvcConfigurationSupport.class)

同时使用第1、3两种,会出现配置失效的问题,因为第1种引入了DelegatingWebMvcConfigurationDelegatingWebMvcConfigurationWebMvcConfigurationSupport的子类。

建议在springboot环境下使用第2种方式,在使用第2种方式时自定义配置方法是实现WebMvcConfigurer接口,在jdk1.8环境下代码数量很少!

个人总结,如有错误望谅解,期待您的指正,谢谢!!

相关文章

网友评论

      本文标题:springboot(2.X)下webmvc配置方式

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