zoukankan      html  css  js  c++  java
  • Error resolving template [index], template might not exist or might not be accessible by any of the configured Template Resolvers

    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 依赖

    1         <!-- Thymeleaf -->
    2         <dependency>
    3             <groupId>org.springframework.boot</groupId>
    4             <artifactId>spring-boot-starter-thymeleaf</artifactId>
    5         </dependency>

    2.application.properties 配置

    1 server.port=8888
    2 spring.mvc.view.prefix=/templates/
    3 spring.mvc.view.suffix=.html

     3.代码实现

    1     @GetMapping("/index")
    2     public String index() {
    3         return "index";
    4     }

    4.文件结构

    解决方案:

    确定自己的pom.xml文件中是否添加resources插件,若是没有进行以下步骤检查

    解决办法:
    1.检查controller中的注解:@RestController是@ResponseBody和@Controller的组合这个注解,返回html页面时应该使用@Controller注解。
    2.检查return中的字符串是否有错误(注意没有 ‘/’ 字符)
    3.检查html页面是否存在
    4.html文件是否存在templates目录下,若是存在自定义的目录下则需要配置

    若是有resources插件,配置如下

    解决办法:
    检查自己的resource标签中是否加入了以html为后缀的资源文件

     1             <resource>
     2                 <directory>src/main/resources</directory>
     3                 <includes>
     4                     <include>**/*.xml</include>
     5                     <include>META-INF/app.properties</include>
     6                     <include>application.properties</include> // 加入配置文件
     7                     <include>**/*.html</include> //加入 html 文件
     8                 </includes>
     9                 <filtering>true</filtering>
    10             </resource>

    最后重新 update 一下项目即可。

  • 相关阅读:
    「luogu2414」[NOI2011]阿狸的打字机
    【模板】KMP算法,AC自动机
    「luogu2336」[SCOI2012]喵星球上的点名
    「luogu2463」[SDOI2008]Sandy的卡片
    【模板】后缀数组
    「luogu1972」 [SDOI2009]HH的项链
    北师大部分题解
    D:Sequence Swapping
    Tinkoff Internship Warmup Round 2018 and Codeforces Round #475 (Div. 2)
    点双连通分量F. Simple Cycles Edges
  • 原文地址:https://www.cnblogs.com/ming-blogs/p/13749368.html
Copyright © 2011-2022 走看看