springboot 整合 html 页面,无法加载到 .html 页面。
错误描述
[2020-09-29 14:01:37.541] [http-nio-8888-exec-1] [ERROR][org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet]] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template [index], template might not exist or might not be accessible by any of the configured Template Resolvers] with root cause
org.thymeleaf.exceptions.TemplateInputException: Error resolving template [index], template might not exist or might not be accessible by any of the configured Template Resolvers
1.maven 依赖
2.application.properties 配置
3.代码实现
4.文件结构
![Error resolving template [index], template might not exist or migh_html](https://s2.51cto.com/images/blog/202205/27143937_629072295963966760.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
解决方案:
确定自己的pom.xml文件中是否添加resources插件,若是没有进行以下步骤检查
解决办法:
1.检查controller中的注解:@RestController是@ResponseBody和@Controller的组合这个注解,返回html页面时应该使用@Controller注解。
2.检查return中的字符串是否有错误(注意没有 ‘/’ 字符)
3.检查html页面是否存在
4.html文件是否存在templates目录下,若是存在自定义的目录下则需要配置
若是有resources插件,配置如下
解决办法:
检查自己的resource标签中是否加入了以html为后缀的资源文件
最后重新 update 一下项目即可。
















