[英]Not getting session attributes in sessionDestroyed() method of HttpSessionListener
[英]How to get Spring globalsession scoped bean in HttpSessionListener (sessionDestroyed method)
所有。 我瀏覽了網絡,但沒有找到適合我的解決方案。
在會話被銷毀之前,我需要從HttpSessionListener
globalsession范圍內的bean訪問信息。
在檢查了會話屬性之后,我找到了一個解決方案,但是看起來並不順利:
MyBean myBean = httpSessionEvent.getSession().getAttribute("scopedTarget."+"myBeanImlp");
我也有單例bean,通過target + proxy包含會話bean,但是通過ctx.getBean("mySingletonBean")
將它們放入sessionDestroyed
,對會話bean的引用在它們內部無效(在sessionDestroyed
調用之前會話bean已被銷毀)
有人知道這種問題的好方法嗎?
我在想我們需要DestructionAwareBeanPostProcessor
東西,但對於會話bean,我可以在其中瀏覽bean,准備銷毀並采取所需的操作。
您可以嘗試將會話偵聽器定義為組件,然后注入ApplicationContext(或所需的bean),然后對其進行訪問。 您可以看看如何使用Spring將依賴項注入HttpSessionListener?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.