初学者在maven spring boot web项目中使用thymeleaf 模板,经常会遇到  “template might not exist or might not be accessible by any of the configured Template Resolvers”这个问题,让人很头疼。其实这个错误的描述很清楚:

第一、模板不存在 ,第二、模板无法被解析器解析

带着这两个问题来找答案:

首先确定在Maven的资源管理文件中  pom.xml确保引入 spring-boot-starter-thymeleaf这个jar包,如果配置中有,它会自动下载到本地库。

        <!-- 引入 thymeleaf 模板依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

接下来在application.properties 中添加如下配置:

spring.thymeleaf.mode=HTML
spring.thymeleaf.cache=true
spring.thymeleaf.enabled=true
spring.thymeleaf.encoding=utf-
spring.thymeleaf.prefix=/resources/templates/
spring.thymeleaf.suffix=.html #文件后缀为.html或.jsp都可以,取决于/resources/templates/下对应的文件

有了以上这两步就没问题了,如下是项目的目录结构

Spring 启动类及MVC的 控制器部分代码:

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.example.bean.User; @Controller
@SpringBootApplication
public class DemoApplication { public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
System.out.print("app init");
} @RequestMapping("/hello")
@ResponseBody
String home() {
System.out.print("hello");
return "Hello ,spring boot!";
} @RequestMapping("/")
public String index() {
System.out.print("index");
return "index";
} @RequestMapping("/userLogin")
public String userLogin(Model model) {
User user = new User("guozhong",30);
model.addAttribute("user",user);
return "userLogin";
}
}

浏览器访问:

template might not exist or might not be accessible by any of the configured Template Resolvers 完美解决的更多相关文章

  1. template might not exist or might not be accessible by any of the configured Template Resolvers

    距离上一篇文章已经很长时间了,最近太忙碌了,今天发布spring boot遇到一个问题,找了好久才找到解决办法,今天贴出来和大家一起分享下,首先看错误信息 HTTP Status 500 - Requ ...

  2. org.thymeleaf.exceptions.TemplateInputException: Error resolving template "/home/index2", template might not exist or might not be accessible by any of the configured Template Resolvers

    org.thymeleaf.exceptions.TemplateInputException: Error resolving template "/home/index2", ...

  3. Spring Boot使用thymeleaf模板时报异常:template might not exist or might not be accessible by any of the configured Template Resolvers

    错误如下: template might not exist or might not be accessible by any of the configured Template Resolver ...

  4. template might not exist or might not be accessible by any of the configured Template Resolvers at org.thymeleaf.engine.TemplateManager.resolveTemplate(TemplateManager.java:869)

    org.thymeleaf.exceptions.TemplateInputException: Error resolving template [code/leading], template m ...

  5. Error resolving template,template might not exist or might not be accessible by any of the configured Template Resolvers

    template might not exist or might not be accessible by any of the configured Template Resolvers at o ...

  6. SpringBoot使用thymeleaf模板时报错:Template might not exist or might not be accessible by any of the configured Template Resolvers

    错误如下:Template might not exist or might not be accessible by any of the configured Template Resolvers ...

  7. Error resolving template “pages”, template might not exist or might not be accessible by any of the configured Template Resolver 或者 springboot使用thymeleaf时报html没有结束标签

    application.properties配置文件 spring.thymeleaf.prefix=classpath:/templates/ spring.thymeleaf.suffix=.ht ...

  8. org.thymeleaf.exceptions.TemplateInputException: Error resolving template "/ template might not exist or might not be accessible by any of the configured

    异常现象:在本地打包部署完全没有问题,资源文件也都可以映射上,但是打包成jar包部署到服务器上时,就一直报异常,异常信息如下: 严重: Servlet.service() for servlet [d ...

  9. 【SpringBoot+Mybatis+thymeleaf报错】Error resolving template "XXX", template might not exist or might not be accessible by any of the configured

    解决方法一: 原因:在使用springboot的过程中,如果使用thymeleaf作为模板文件,则要求HTML格式必须为严格的html5格式,必须有结束标签,否则会报错. 在application.y ...

随机推荐

  1. 1. jenkins 安装部署

    参考文档: https://jenkins.io/zh 准备环境 - jdk          路径: https://www.oracle.com/technetwork/java/javase/a ...

  2. Lodop打印表格带页头页尾 高度是否包含页头页尾 转载

    通过设置TableHeightScope,可以实现对ADD_PRINT_TABLE,表格带页头页尾,查看本博客另一篇博文:Lodop打印表格带页头页尾 自动分页每页显示头尾 超文本超过打印项高度,会自 ...

  3. centos7编译安装php 遇到的问题

    centos7 编辑安装php遇到的问题: ./configure 配置遇到的No package 'libxml-2.0' found缺失libxml2.0 库,解决方法: yum -y insta ...

  4. 网络yum源配置

    系统环境:CentOS7 [1] 首先备份/etc/yum.repos.d/CentOS-Base.repo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum ...

  5. 关于git设置多个账号的问题,ideal中clone项目

    一.排坑 1.ping github.com超时.修改C:\Windows\System32\drivers\etc的hosts文件,添加 # GitHub地址 192.30.255.112 gith ...

  6. redixdb 基于redis 协议的实时key-value 存储

    redixdb 是一个基于redis 协议搞的一个实时key value 处理的轻量级应用,支持多种后端 存储模型. 以下是一个小版的容器镜像(官方的太大了) dockerfile   FROM go ...

  7. B1038 统计同成绩学生 (20 分)

    #include<iostream> #include<cstring> using namespace std; const int maxn = 10010; int sc ...

  8. 基于paramiko将文件上传到服务器上

    通过安装使用paramiko模块,将本地文件上传到服务器上 import paramiko import datetime import os hostname = '服务器ip' username ...

  9. python3中用django下载文件,中文名乱码怎么办?

    前段时间被某个前端小可爱鄙视了一下,说我博客都一年不更新了,我不服,明明还有俩月才到一年呢.不过说是这么说,还是要更新一下的. 以上都是借口,下面开始正文.     我公司的某个内部系统,用djang ...

  10. swagger案例Swagger案例

    pom <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework ...