Thymeleaf 缓存设置为 false 不起作用

问题描述 投票:0回答:3

我正在开发一个 Spring 应用程序。 项目配置如下:

  • spring-dev-tools 依赖是 Maven 依赖之一
  • thymeleaf依赖是通过spring-boot-starter添加的,即
    org.springframework.boot:spring-boot-starter-thymeleaf
  • 我已使用
    spring.thymeleaf.cache=false
  • 明确禁用了模板缓存
  • src/main/resources
    文件夹在我的 IntelliJ IDEA 项目中被标记为资源。

我正在使用 IntelliJ IDEA 项目来运行该应用程序。 当我运行该应用程序时,我可以在控制台输出中看到:

LiveReload server is running on port 35729

虽然我的所有配置似乎都是正确的,但正在运行的应用程序在运行时没有加载我对模板所做的任何更改。

spring spring-boot thymeleaf
3个回答
7
投票

如果您正在使用

Spring Tool Suite 4
,则需要在
application.properties
中执行以下操作以禁用
cache
中的
Thymeleaf

spring.thymeleaf.cache=false
spring.thymeleaf.prefix=file:src/main/resources/templates/

添加

spring.thymeleaf.prefix
值对我有用。

有关解决方案的更多信息:

https://github.com/spring-projects/spring-boot/issues/34#issuecomment-316295791


2
投票

LiveReload 服务器仅在类路径上的文件之一被修改时加载任何更改Spring Doc
虽然我有资源,包含模板文件夹的文件夹,但在类路径上,对模板文件夹中的 html 文件的更改不会反映在正在运行的应用程序中。
对我有用的是将

src/main/resources/templates
添加到类路径,即在 IntelliJ 中标记为资源

谢谢


0
投票

对我来说添加这两个属性是有效的:

spring.thymeleaf.cache=false
spring.devtools.restart.additional-paths=file:src/main/resources/templates/

我使用的是STS 4.20.1

© www.soinside.com 2019 - 2024. All rights reserved.