template might not exist or might not be accessible by any of the configured Template Resolvers 完美解决
初学者在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 完美解决的更多相关文章
- template might not exist or might not be accessible by any of the configured Template Resolvers
距离上一篇文章已经很长时间了,最近太忙碌了,今天发布spring boot遇到一个问题,找了好久才找到解决办法,今天贴出来和大家一起分享下,首先看错误信息 HTTP Status 500 - Requ ...
- 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", ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 【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 ...
随机推荐
- nginx配置多个静态资源
#user nobody; worker_processes ; worker_cpu_affinity ; #error_log logs/error.log; #error_log logs/er ...
- docker研究-3 docker简介和基本操作
Docker是PaaS供应商dotCloud开源的一个基于LXC 的高级容器引擎,源代码托管在 GitHub 上, 基于Go语言开发并遵从Apache 2.0协议开源.Docker 是通过内核虚拟化技 ...
- 模仿51cto搜索框
做这个demo遇见的问题 1==>input type=submit有默认样式 padding:1px 6px所以将他去除 2==>input submit有默认样式 去除默认边框 bor ...
- fatal error C1083: 无法打开包括文件: “Halcon.h”: No such file or directory
这个文件是有包括的.但编译时报错. 解决方法:我把debug模式改为release模式就好了.
- 201871010135 张玉晶《面向对象程序设计(java)》第十六周学习总结
第一部分:总结教材14.1-14.3知识内容 并发 • 线程的概念 • 中断线程 • 线程状态 • 多线程调度 • 线程同步 一.线程的概念 1. 程序是一段静态的代码,它是应用程序执行的蓝本. 2. ...
- webapi序列化控制
我们都知道在使用WebApi的时候Controller会自动将Action的返回值自动进行各种序列化处理(序列化为json,xml等),但是如果Controller的自动序列化后的结果不是我们想要的该 ...
- linux翻页及字符串搜索操作
向下翻动一屏幕: space, ctrl + f, ctrl + v, ctrl + F 向下翻动半屏: d, ctrl + D 向下翻动一行: 回车, e, j 向上翻动一屏幕: b, ctrl + ...
- MacbookPro升级10.15 Catalina之后无法读写NTFS
冲着Sidecar的双屏功能,乐呵呵的跑去升级了10.15,结果就悲剧了. 所有移动硬盘和U盘都写不了,无奈只好上网找办法,目前找到一个便宜的方法: 共2步: Step 1:编写fstab文件 使用T ...
- [LeetCode] 53. Maximum Subarray 最大子数组
Given an integer array nums, find the contiguous subarray (containing at least one number) which has ...
- Debian/Ubuntu下安装Apache的Mod_Rewrite模块的步骤
启用 Mod_rewrite 模块:sudo a2enmod rewrite 另外,也可以通过将 /etc/apache2/mods-available/rewrite.load 连接到 /etc/a ...