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. ...
随机推荐
- 【转载】row cache lock
转自:http://blog.itpub.net/26736162/viewspace-2139754/ 定位的办法: --查询row cache lock等待 select event,p1 ...
- 前端框架本质之探究——以Vue.js为例
问:我们在使用Vue时,实际上干了什么? 答:实际上只干了一件事——new了一个Vue对象.后面的事,都交由这个对象自动去做.就好像按了下开关,机器跑起来了,剩下的事就不用我们再操心了. 各位 ...
- 通过代码定义shape/selector
public class DrawableUtil { /** * 定义一个shape资源 * * @param rgb * @param corneradius * @return */ publi ...
- Java学习图
- 多条SQL语句对查询结果集的垂直合并,以及表设计时如何冗余字段
需求引入 你有一个销售单表A 和一个销售单详情表B 和一个收付款记录表C A---->B 一对多 A---->C一对多 如果一个销售单有两个详情,三条收款记录 对一个销售单 我们想查询 ...
- 简单读!spring-mvc源码之穿越http请求
相信spring-mvc这种被玩坏了的架构理念,大家都烂熟于胸了,不过还是想来扒一扒他的细节. 一个http请求,怎么样被 spring 接收,又怎样做出响应呢? 一般地,我们会配置一个 web.xm ...
- Spark基础-scala学习(四、函数式编程)
函数式编程 将函数赋值给变量 匿名函数 高阶函数 高级函数的类型推断 scala的常用高阶函数 闭包 sam转换 currying函数 return 将函数赋值给变量 scala中的函数是一等公民,可 ...
- php--isset()、is_null() 、empty()
开发中经常会遇到验证某个参数是否是null或者是否为空. 一.isset().is_null() .empty() : isset():检测变量是否设置,并且不是 NULL.如果变量没有赋值 或者 变 ...
- Oracle递归查询start with connect by prior
一.基本语法 connect by递归查询基本语法是: select 1 from 表格 start with ... connect by prior id = pId start with:表示以 ...
- python基础-字符串(6)
一.引言 当打来浏览器登录某些网站的时候,需要输入密码,浏览器把密码传送到服务器后,服务器会对密码进行验证,其验证过程是把之前保存的密码与本次传递过去的密码进行对比,如果相等,那么就认为密码正确,否则 ...