首页 > 其他分享 >Springboot报错:Could not resolve view with name 'index' in servlet with name 'dispatche

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

时间:2023-04-11 11:45:56浏览次数:50  
标签:index name viewResolver application 报错 InternalResourceViewResolver 注解 jsp

该异常是因为用定义了带@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

 

标签:index,name,viewResolver,application,报错,InternalResourceViewResolver,注解,jsp
From: https://www.cnblogs.com/super-chao/p/17305726.html

相关文章