第一步:pom.xml加入依赖

     <!-- HTML templates-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
如果出现错误 如下..
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'viewResolver' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration$Thymeleaf3Configuration$Thymeleaf3ViewResolverConfiguration': Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration$ThymeleafDefaultConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultTemplateResolver' defined in class path resource [org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration$Thymeleaf3Configuration$DefaultTemplateResolverConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver]: Factory method 'defaultTemplateResolver' threw exception; nested exception is java.lang.NoSuchMethodError: org.thymeleaf.templateresolver.TemplateResolver.checkNotInitialized()V
  
我们应该修改 Properties配置
    <properties>
  <thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
  <thymeleaf-layout-dialect.version>2.1.1</thymeleaf-layout-dialect.version>
</properties>

  

第二步: 修改yml文件

spring:
thymeleaf:
mode: HTML5
encoding: utf-8
content-type: text/html
cache: false

第三步:修改Controller

    @GetMapping("/hello")
String test(HttpServletRequest request) {
//逻辑处理
request.setAttribute("name", "java");
return "/hello";
}
第四步:修改html 放在resource/templates/hello.html
<!DOCTYPE html >
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Hello World!</title>
</head>
<body>
<span th:text="'Welcome to our application, ' + ${name} + '!'"></span>
</body>
</html>
第五步:浏览器输入 看效果
												

Spring boot Thymeleaf 配置的更多相关文章

  1. 玩转spring boot——properties配置

    前言 在以往的java开发中,程序员最怕大量的配置,是因为配置一多就不好统一管理,经常出现找不到配置的情况.而项目中,从开发测试环境到生产环境,往往需要切换不同的配置,如测试数据库连接换成生产数据库连 ...

  2. spring boot + thymeleaf 3 国际化

    在给spring boot 1.5.6 + thymeleaf 3进行国际化时,踩了一个坑(其实不止一个). 现象: 看到了吧, 就是取值的key, 后面被加了_en_US 或 _zh_CN, 以及前 ...

  3. Spring Boot自动配置与Spring 条件化配置

    SpringBoot自动配置 SpringBoot的自动配置是一个运行时(应用程序启动时)的过程,简化开发时间,无需浪费时间讨论具体的Spring配置,只需考虑如何利用SpringBoot的自动配置即 ...

  4. Spring Boot 揭秘与实战 附录 - Spring Boot 公共配置

    Spring Boot 公共配置,配置 application.properties/application.yml 文件中. 摘自:http://docs.spring.io/spring-boot ...

  5. spring boot: thymeleaf模板引擎使用

    spring boot: thymeleaf模板引擎使用 在pom.xml加入thymeleaf模板依赖 <!-- 添加thymeleaf的依赖 --> <dependency> ...

  6. Spring Boot 日志配置

    Spring Boot 日志配置 默认日志 Logback: 默认情况下,Spring Boot会用Logback来记录日志,并用INFO级别输出到控制台.在运行应用程序和其他例子时,你应该已经看到很 ...

  7. Spring Boot自动配置原理(转)

    第3章 Spring Boot自动配置原理 3.1 SpringBoot的核心组件模块 首先,我们来简单统计一下SpringBoot核心工程的源码java文件数量: 我们cd到spring-boot- ...

  8. spring boot + thymeleaf 乱码问题

    spring boot + thymeleaf 乱码问题 hellotrms 发布于 2017/01/17 15:27 阅读 1K+ 收藏 0 答案 1 开发四年只会写业务代码,分布式高并发都不会还做 ...

  9. Spring Boot 自动配置的原理、核心注解以及利用自动配置实现了自定义 Starter 组件

    本章内容 自定义属性快速入门 外化配置 自动配置 自定义创建 Starter 组件 摘录:读书是读完这些文字还要好好用心去想想,写书也一样,做任何事也一样 图 2 第二章目录结构图 第 2 章 Spr ...

随机推荐

  1. dgraph 基本查询语法 三

    这部分主要是查询块.查询变量.聚合操作 多名称查询 实际上就是类似多个查询数据的拼接 格式: { caro(func: allofterms(name@en, "Marc Caro" ...

  2. 【转】每天一个linux命令(43):killall命令

    原文网址:http://www.cnblogs.com/peida/archive/2012/12/21/2827366.html Linux系统中的killall命令用于杀死指定名字的进程(kill ...

  3. 理解js事件循环(event loop)

    队列:先进先出 栈:后进先出 javascript的Event Loop 和 Node.js的Event Loop 区别: js(运行在浏览器),有主线程.异步任务队列的概念: node.js使用li ...

  4. HttpFileCollection类

    最近在学HttpRequest类搞文件上传的时候看到Request.Files返回了HttpFileCollection 这个类的一个对象,这个类用于获取浏览器上传的文件集合,在文件上传的时候可以通过 ...

  5. ES(6): access elasticsearch via curl

    curl是一个非常实用的.用来与服务器之间传输数据的工具:支持的协议包括 (DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, ...

  6. visual studio 2010 c++ fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或

    解决方案: 1,在项目 上 选择 “视图”- “属性页” 2,选择 “配置属性” - “清单工具” - “输入输出”,将 “嵌入清单”的值设置为 “否”

  7. PHP与MySqli

    一:链接数据库: $mysqli=@new mysqli("localhost","root","123456","msqldb& ...

  8. gdb 调试(设置变量)(六)

    一旦使用GDB挂上被调试程序,当程序运行起来后,你可以根据自己的调试思路来动态地在GDB中更改当前被调试程序的运行线路或是其变量的值,这个强大的功能能够让你更好的调试你的程序,比如,你可以在程序的一次 ...

  9. priority_queue使用方法详解

    1.介绍 优先队列是一种容器,它可以使得其第一个元素始终是它包含的最大元素,具体实现原理是堆排序. 它支持以下操作: empty() size() top() push() pop() 在使用prio ...

  10. 利用spring的ApplicationListener实现springmvc容器的初始化加载--转

    1.我们在使用springmvc进行配置的时候一般初始化都是在web.xml里面进行的,但是自己在使用的时候经常会测试一些数据,这样就只有加载spring-mvc.xml的配置文件来实现.为了更方便的 ...