gpt4 book ai didi

spring - 使用 Spring MVC 和 Thymeleaf 更新 View 而无需重新部署应用程序

转载 作者:行者123 更新时间:2023-11-28 22:42:28 24 4
gpt4 key购买 nike

我正在使用 Spring MVC 3.2、Thymeleaf、Thymeleaf 方言和 Tomcat,每次我更改 View 时,我都不想重新部署我的应用程序。根据其他人的建议,我正在设置:

<property name="cacheable" value="false"/> 

在模板解析器中,但它不工作。完全重新加载 (CTRL + F5) 也没有效果。

这是我完整的 Thymeleaf 配置:

<!-- Thymeleaf template engine -->
<bean id="templateResolver"
class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
<property name="prefix" value="/WEB-INF/templates/" />
<property name="suffix" value=".html" />
<property name="templateMode" value="HTML5" />
<property name="cacheable" value="false"/>
</bean>

<bean id="templateEngine"
class="org.thymeleaf.spring3.SpringTemplateEngine">
<property name="templateResolver" ref="templateResolver" />
<!-- These lines add the dialect to Thymeleaf -->
<property name="additionalDialects">
<set>
<bean class="nz.net.ultraq.thymeleaf.LayoutDialect"/>
</set>
</property>
</bean>

<bean class="org.thymeleaf.spring3.view.ThymeleafViewResolver">
<property name="templateEngine" ref="templateEngine" />
</bean>

我还能做些什么来解决这个问题吗?

最佳答案

这取决于很多事情,主要取决于您更新 View 的“位置和方式”。如果您使用的是 IDE(Netbeans 或 Eclipse),它主要取决于 IDE 本身和部署过程。

磁盘上的当前组织:

Source directories => [ on build ] => target or build directories => [ on deploy ] => tomcat directories

但 IDE 经常试图对开发人员友好,可能目标目录和 tomcat 目录相同。但它也可能取决于 IDE 及其配置。此外,当您将文件保存在源 webapp 下时,IDE 可能会自动将它们复制到目标。

但这不能由<property name="cacheable" value="false"/>保证Thymeleaf 配置。它所保证的是,如果在 tomcat 目录中更改了模板,下一个请求将使用它。

因此,要确定问题真正出在哪里,您必须找到 tomcat 实际获取模板的位置以及是否修改了那些模板。

(我什至没有谈到浏览器缓存...)

关于spring - 使用 Spring MVC 和 Thymeleaf 更新 View 而无需重新部署应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25227625/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com