SpringBoot 项目 @EnableWebMvc 和@EnableAutoConfiguration注解一些坑总结

关于springBoot项目中报错:

javax.servlet.ServletException: Could not resolve view with name 'xxx' in servlet with name 'dispatcherServlet',

有可能是因为如下使用方式造成的无法使用视图解析器,请自行排查。

 

使用方式结果
@EnableWebMvc + extends WebMvcConfigurationAdapter

× 会屏蔽@EnableAutoConfiguration注解

@EnableWebMvc + implements WebMvcConfigurer× 会屏蔽@EnableAutoConfiguration注解
extends WebMvcConfigurationSupport× 会屏蔽@EnableAutoConfiguration注解
extends DelegatingWebMvcConfiguration× 会屏蔽@EnableAutoConfiguration注解
extends WebMvcConfigurationAdapter(springBoot1.5以前,之后已废弃)√ 不会屏蔽@EnableAutoConfiguration注解

implements WebMvcConfigurer(springBoot2.0以后)

一些实现可以参考 WebMvcConfigurer接口配置实现自定义web 和 SpringBoot系列——WebMvcConfigurer介绍 及

精通SpringBoot——第三篇:详解WebMvcConfigurer接口 

√ 不会屏蔽@EnableAutoConfiguration注解

最后两句总结:

使用 @EnableWebMvc 注解,需要以编程的方式指定视图文件相关配置;

使用 @EnableAutoConfiguration 注解,会读取 application.properties 或 application.yml 文件中的配置。

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值