[spring-boot] thymeleaf 热交换
来源:互联网 发布:苹果mac装win7系统 编辑:程序博客网 时间:2024/05/04 13:07
使用spring boot main方法启动时,修改了thymeleaf文件后,热交换不能起作用,每次修改都需要重新启动服务,非常不方便,google搜索到方法,特分享于此。
原文:https://github.com/spring-projects/spring-boot/issues/34
The default template resolver registered by spring is classpath based, meaning that it loads the templates from the compiled resources. That’s why it requires a recompilation. Thymeleaf includes a file-system based resolver, this loads the templates from the file-system directly not through the classpath (compiled resources). Spring Boot allows us to override the default resolver by making a bean with the name defaultTemplateResolver, here is a full example:
@Configurationpublic class ThymeleafConfiguration { @Bean public ITemplateResolver defaultTemplateResolver() { TemplateResolver resolver = new FileTemplateResolver(); resolver.setSuffix(".html"); resolver.setPrefix("path/to/your/templates"); resolver.setTemplateMode("HTML5"); resolver.setCharacterEncoding("UTF-8"); resolver.setCacheable(false); return resolver; }}
大意是默认情况下,spring boot是使用class path寻找thymeleaf文件的,所以加载的是已编译好的thymeleaf文件。spring boot 允许使用file system based resolver 从文件系统加载thymeleaf文件,所以只要配置使用file system based resolver,修改thymeleaf文件后可立即生效。
方法如下:
@Configurationpublic class ThymeleafConfig { @Bean public ITemplateResolver defaultTemplateResolver() { TemplateResolver resolver = new FileTemplateResolver(); resolver.setSuffix(".html"); resolver.setPrefix("src/main/resources/templates/"); resolver.setTemplateMode("HTML5"); resolver.setCharacterEncoding("UTF-8"); resolver.setCacheable(false); return resolver; }}
- [spring-boot] thymeleaf 热交换
- Spring Boot + Gradle + Thymeleaf
- spring boot 整合 thymeleaf
- spring boot vue Thymeleaf
- spring boot thymeleaf 用法
- Spring Boot使用Thymeleaf
- Spring-Boot thymeleaf异常
- spring-boot集成thymeleaf
- Spring Boot整合thymeleaf
- Spring Boot+Spring Security+Thymeleaf
- Thymeleaf系列一 Spring boot 集成Thymeleaf
- Spring Boot (三) Spring Boot for thymeleaf
- spring boot thymeleaf 入门 demo
- spring-boot--使用thymeleaf模板
- spring-boot--使用thymeleaf模板
- Spring Boot使用thymeleaf模板
- spring-boot--整合thymeleaf模板
- Spring Boot 12之 thymeleaf
- 子数组和问题,和被某个数整除
- 来玩欢乐斗地主!纸牌游戏例子的ObserverPattern----观察者模式
- Linux进程间的通信方式之管道
- CSUOJ 1945 最简单的题目 背包问题
- 使用apt-get install安装软件时,提示could not get lock /var/lib/dpkg/lock
- [spring-boot] thymeleaf 热交换
- css笔记:HTML文档中应用css样式的方法总结
- PostgreSQL模糊匹配走索引
- 卡特兰数
- AndroidStudio中mipmap目录和drawable目录有什么区别
- swift3.1 快速上手系列(一)
- Linux 学习(六)--- 文件权限的操作
- (13) FFMPEG结构体分析:AVFormatContext
- (158)材质编辑器UI