springbooot2 thymeleaf 配置以及加载资源文件。Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration)
最近在学习springbooot2 和 thymeleaf
程序文件

application.properties文件配置:
#thymeleaf
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.cache=false
spring.thymeleaf.servlet.content-type=text/html
spring.thymeleaf.enabled=true
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.mode=HTML
spring.thymeleaf.check-template-location=true
# 静态文件请求匹配方式
spring.mvc.static-path-pattern=/**
# 修改默认的静态寻址资源目录
spring.resources.static-locations = classpath:/templates/,classpath:/resources/,classpath:/static/,classpath:/public/
#热部署生效
spring.devtools.restart.enabled=true
在编译的时候,发现一直报这个错误:
Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration)
之后再网上找了各种答案,发现都不能使用
-------------------------------------------------------------------------------------------------------------------
下面是正确的方案:
在pom.xml中引入如下配置
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<resources>
<resource>
<!--加载资源目录-->
<directory>src/main/resources</directory>
<includes>
<!--加载配置文件-->
<include>**/*.xml</include>
<include>**/*.properties</include>
<!--加载模板文件-->
<include>**/*.html</include>
<!--加载静态文件-->
<include>/static/</include>
</includes> </resource>
</resources>
</build>
在pom.xml中引入的文件,这样application.properties文件中可注释文件路径配置。
server.port=9099
#thymeleaf
#spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.cache=false
spring.thymeleaf.servlet.content-type=text/html
spring.thymeleaf.enabled=true
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.mode=HTML
spring.thymeleaf.check-template-location=true
# 静态文件请求匹配方式
#spring.mvc.static-path-pattern=/**
# 修改默认的静态寻址资源目录
#spring.resources.static-locations = classpath:/templates/,classpath:/resources/,classpath:/static/,classpath:/public/
#热部署生效
spring.devtools.restart.enabled=true
LoginController中:
package com.java.seckill.controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; @Controller
@RequestMapping("/login")
public class LoginController {
@RequestMapping("/index")
public String Index() {
return "login";
} @RequestMapping("/login")
@ResponseBody
public Boolean login(){
return true;
}
}
直接访问:http://localhost:9099/login/index
springbooot2 thymeleaf 配置以及加载资源文件。Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration)的更多相关文章
- spring加载资源文件中classpath*与classpath的区别
在spring和MyBatis继承的时候,配置mapperLocations.一开始配置是这样的. 需要加载路径为com/thomas/base/mapper和com/thomas/bu/mapper ...
- Spring boot 国际化自动加载资源文件问题
Spring boot 国际化自动加载资源文件问题 最近在做基于Spring boot配置的项目.中间遇到一个国际化资源加载的问题,正常来说只要在application.properties文件中定义 ...
- Style样式的四种使用(包括用C#代码动态加载资源文件并设置样式)
Posted on 2012-03-23 11:21 祥叔 阅读(2886) 评论(6) 编辑 收藏 在Web开发中,我们通过CSS来控制页面元素的样式,一般常用三种方式: 1. 内联样式 ...
- Maven,预加载资源文件
预加载资源文件需要先启用功能: <build> <resources> <resource> <directory>src/main/resources ...
- 动态加载资源文件(ResourceDictionary)
原文:动态加载资源文件(ResourceDictionary) 在xaml中控件通过绑定静态资源StaticResource来获取样式Style有多种方式: 1.在项目的启动文件App中<App ...
- Java加载资源文件的两种方法
处理配置文件对于Java程序员来说再常见不过了,不管是Servlet,Spring,抑或是Structs,都需要与配置文件打交道.Java将配置文件当作一种资源(resource)来处理,并且提供了两 ...
- PyQt5(5)——加载资源文件
在实际中我们需要美化界面,就需要许多的自定义图片. 但是我们发现直接导入图像使用,等程序运行时会报错.???? 这就需要建立资源文件并且加载它们,程序就可以顺利运行了. 设计界面是如何加载资源文件呢? ...
- NHibernate动态加载资源文件
最近做项目,又用到了以前做过的ORM框架--NHibernate. 此次想要实现的目标: 1.简单SQL用NHibernate的Session的CRUD方法实现 2.复杂SQL用Native SQL实 ...
- Java加载资源文件几种方法
from: http://andyzhu.blog.51cto.com/4386758/775836/ import java.net.URL; import org.springframework. ...
随机推荐
- 报错:Maximum call stack size exceeded
最后通过查看一篇别人的博客,通过对照,发现我把参数值写反了,把参数a的值写成了参数b的值.详情可以看如下博客: https://www.cnblogs.com/dunitian/p/5865725.h ...
- swarm集群日常部分操作
docker swarm: 1)查看集群使用docker info 或 docker node ls 查看集群中的相关信息 2)swarm集群中node的availability状态可以为 activ ...
- Vipe-技术选型
1.AOP,IOC框架-Spring 选择Spring是最不需要考虑的.应该90%以上的JAVA项目都有用Spring. 2.ORM框架-Mybatis Mybatis入门比较简单,并且对SQL语法的 ...
- Spring-Data-Jpa环境配置与实际应用
上次我们讲述了<Spring-Data-Jpa概述与接口>,接下来我们再讲讲Spring-Data-Jpa环境配置与实际应用. Spring-Data 方法定义规范与使用配置 简单条件查询 ...
- wordpess设置回复可见
easy2hide 是一个不错的隐藏部分内容,评论后可见的插件,可在插件安装后台搜索 easy2hide 在线安装,或者在此下载 easy2hide. 在编辑文章的时候,切换到html文本编辑模式 测 ...
- @vue/cli 构建得项目eslint配置
如下:package.json // package.json { "name": "ecommerce-mall-front", "version& ...
- GenericFactoryMethod泛型工厂模式实现简单IOC功能
1.简介 泛型工厂理论上不算Gof23中设计模式之一,但是也算是一种非常好的设计模式,个人认为,废话不多说,先写个简单的抽象工厂,在写一个泛型工厂的例子来比较抽象和泛型的区别. 2.实战 还是房屋和道 ...
- elasticsearch 操作
文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html 客户端:https://www.elasti ...
- 全网最详细的最新稳定OSSEC搭建部署(ossec-server(CentOS7.X)和ossec-agent(CentOS7.X))(图文详解)
不多说,直接上干货! 前言 写在前面的话,网上能够找到一些关于ossec方面的资料,虽然很少,但是总比没有强,不过在实际的使用过程中还是会碰到许多稀奇古怪的问题.整理整理我的使用过程,就当做一篇笔记吧 ...
- Python快速学习03:运算 & 缩进和选择
前言 系列文章:[传送门] 这篇昨晚本来要出的,去搭了帐篷,在学校的屋顶上. 运算 运算,不得不说的是运算符. 数学 +, -, *, /, **, %,// 判断 ==, !=, >, > ...