Springboot报错:Could not resolve view with name 'index' in servlet with name 'dispatcherServlet'

该异常是因为用定义了带@EnableWebMvc注解的配置类后发生的,在带该注解的配置类中加入下面的代码就可以了:

@Bean
public InternalResourceViewResolver viewResolver() {
    InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
    viewResolver.setPrefix("/WEB-INF/jsp/");
    viewResolver.setSuffix(".jsp");
    return viewResolver;
}

有了这段代码在application.yml中的下面的配置就没有必要了

spring: 
  mvc:
    view:
      prefix: /WEB-INF/
      suffix: .jsp

使用 @EnableWebMvc 注解,需要以编程的方式指定视图文件相关配置;
使用 @EnableAutoConfiguration 注解,会读取 application.properties 或 application.yml 文件中的配置。 

参考:

https://blog.csdn.net/father_Blogger/article/details/89352479

https://www.jianshu.com/p/403fcb340257

 

posted @   super超人  阅读(3554)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
历史上的今天:
2018-04-11 echarts仪表盘
点击右上角即可分享
微信分享提示