关于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介绍 及 | √ 不会屏蔽@EnableAutoConfiguration注解 |
最后两句总结:
使用 @EnableWebMvc 注解,需要以编程的方式指定视图文件相关配置;
使用 @EnableAutoConfiguration 注解,会读取 application.properties 或 application.yml 文件中的配置。
本文探讨了在SpringBoot项目中遇到的视图解析错误,详细分析了不同配置方式对@EnableAutoConfiguration注解的影响,提供了避免错误的有效策略。
5万+

被折叠的 条评论
为什么被折叠?



