初学者在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. Git学习笔记1-Git基础

    1.创建版本库 $ mkdir /d/learngit #创建空目录 $ cd learngit #进入目录 $ git init #将该目录初始化成Git仓库 2.配置信息 1)配置用户信息: $ ...

  2. linux 中断底半部机制对比(任务队列,工作队列,软中断)--由linux RS485引出的血案【转】

    转自:http://blog.chinaunix.net/uid-20768928-id-5077401.html 在LINUX RS485的使用过程中,由于各种原因,最后不得不使用中断底半部机制的方 ...

  3. Linux(CentOS)上,安装了Apache(httpd)后,其他的电脑无法访问的原因

    今天试了下在虚拟机上利用CentOS系统的yum命令安装好了httpd(apache2.2),然后在windows系统下访问此虚拟机的ip地址,却访问不了. 因为前段时间有知道过iptable的限制, ...

  4. 【转】前后端分离的项目如何部署发布到Linux

    前后端分离的项目如何部署发布到Linux 前期准备 1.服务器的基本配置信息2.本机远程连接服务器的工具(xshell.xftp或者mobaXterm等等,看你自己喜欢) 第一步:部署环境 1.安装j ...

  5. SVN服务器_客户端下载和安装

    SVN服务器下载和安装 1.登录 http://subversion.apache.org/packages.html 在该页面可以看到SVN为各种操作系统提供的服务端,单击Win32Svn链接就会导 ...

  6. MySQL数据库的下载与安装

    1.百度:MySQL,点击MySQL官网 2. 进入官网后,点击DOWNLOADS,然后点击Windows 3.点击MySQL Installer 4.下载第二个MSI文佳,点击downloads 5 ...

  7. flutter:Could not download kotlin-gradle-plugin.jar

    我们可以看到是flutter的外部依赖:kotlin-gradle-plugin-1.2.71 下载不了,下面我介绍使用手动下载的方式去解决: 首先,看到flutter项目目录,注意我标出的是运行项目 ...

  8. Spring Cloud微服务安全实战_4-2_常见的微服务安全整体架构

    这个图适用于中小公司的微服务架构 微服务:SpringBoot 写的Rest服务 服务注册与发现:微服务所必备的.每个微服务都会到上边去注册.不管是微服务之间的调用,还是服务网关到微服务的转发,都是通 ...

  9. [LeetCode] 104. Maximum Depth of Binary Tree 二叉树的最大深度

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

  10. C实现简单的xml格式文件

    今天在工作中遇到了一个需要处理xml格式的字符串,需求是修改某个固定的value值,并且还要把这个xml的key和value按照原本的格式在推送回去. 如果使用库,就显得太臃肿了,就想写个简单的dem ...