gpt4 book ai didi

java - Spring Boot应用程序请求处理后的清理方法

转载 作者:行者123 更新时间:2023-12-02 10:20:23 24 4
gpt4 key购买 nike

如何在 Spring Boot 应用程序中的请求完成过程后实现清理方法,以清除线程本地数据等数据

我尝试使用ServletRequestListener.requestDestroyed api,但请求完成后它没有被命中

最佳答案

一个可能的答案是您忽略了注册监听器。 Servlet javadocs说:

In order to receive these notification events, the implementation class must be either declared in the deployment descriptor of the web application, annotated with WebListener, or registered via one of the addListener methods defined on ServletContext.

使用 Spring 可能还有其他方法来实现这一点;例如使用处理程序拦截器;请参阅Remove ThreadLocal object within a Spring MVC website?

如果您使用普通 servlet(没有 Spring MVC 基础设施),另一种方法是在 servlet 的 service 方法或 doXxx 方法中进行清理。或者在 servlet 前面的 Filter 中。

关于java - Spring Boot应用程序请求处理后的清理方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54385689/

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