【发布时间】:2019-07-17 14:33:45
【问题描述】:
我创建了一个启用 i18n 的 Spring Boot 2.1.3 应用程序,添加了开发工具,并安装了 Firefox LiveReload 扩展。不幸的是,当我更改我的 Thymeleaf 模板或 i18n 消息时,它并没有改变。 Spring Boot documentation 似乎暗示您需要做的就是安装 devtools,它会禁用静态资源的缓存。
这是我创建应用程序时所做的:
mkdir bootiful-i18n
cd bootiful-i18n
http https://start.spring.io/starter.zip dependencies==web,thymeleaf -d | tar xvz
然后我创建了一个HomeController.java:
package com.example.demo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class HomeController {
@GetMapping("/")
String home() {
return "home";
}
}
我在src/main/resources/templates/home.html 创建了一个 Thymeleaf 模板:
<html xmlns:th="http://www.thymeleaf.org">
<body>
<h1 th:text="#{title}"></h1>
<p th:text="#{message}"></p>
</body>
</html>
我在src/main/resources 中添加了一个messages.properties 文件:
title=Welcome
message=Hello! I hope you're having a great day.
这一切都很好。为了启用热重载,我将 devtools 添加到 pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
并安装了LiveReload extension for Firefox。
我重新启动服务器,启用 LiveReload 并导航到 http://localhost:8080。我尝试更改并保存home.html 和messages.properties 并刷新我的浏览器。浏览器中的输出不会改变。我还需要做些什么来禁用 Spring Boot 2.1 中 Thymeleaf 模板和消息包的缓存吗?
【问题讨论】:
标签: java spring spring-boot thymeleaf