【发布时间】:2026-01-11 09:10:02
【问题描述】:
我们在发送 flash 属性时遇到问题。 我们在本地测试了 flash 属性,它可以工作。 但是我们部署到 Azure 之后,flash 属性就不起作用了。
该应用使用 Spring Boot 和 Thymleaf!
也许 Azure 禁用了这个功能? 我们不知道。
Java类方法:
public void handleInvitationResult(RedirectAttributes redirectAttributes, InvitationResult invitationResult) {
redirectAttributes.addFlashAttribute("success", invitationResult.isSuccess());
if (!invitationResult.isSuccess()) {
redirectAttributes.addFlashAttribute("exception", invitationResult.getErrorMessage());
}
}
Html Thymleaf 文件:
<div th:if="${success}" class="mt-3">
<div class="alert alert-success" role="alert">
<i class="fas fa-exclamation-circle pr-2"></i><span th:text="#{invitation.success}"></span>
</div>
</div>
找到解决方案:
发现问题,我们必须更新 Spring Boot:2.3.5.RELEASE -> 2.5.4
【问题讨论】:
-
请将代码发布为代码而不是图像,因为它们不可读。
-
我复制了代码,但无法复制整个文件。但问题不在于代码。它在本地运行,我们尝试使用 docker 运行并且也能正常运行。
-
Flash 属性,取决于使用 azure 的会话(默认情况下),您可能有多个实例,并且在重定向之后,您可能会在另一个实例中结束,该实例没有会话,因此没有会话属性.要么使用不同的 Flash 实现(例如 cookie,尽管您需要自己编写它们)或配置 azure 以使用粘性会话(即根据会话 cookie 反复路由到同一服务器)。
-
我们没有多个实例,也没有使用负载均衡器。
-
我们也开启了 ARR 亲和性,但仍然无法正常工作。
标签: spring spring-boot azure azure-web-app-service azure-webapps