【问题标题】:How to get Spring globalsession scoped bean in HttpSessionListener (sessionDestroyed method)如何在 HttpSessionListener(sessionDestroyed 方法)中获取 Spring globalsession 范围的 bean
【发布时间】:2015-06-29 04:54:59
【问题描述】:

全部。 我浏览了网页,但没有找到适合我的解决方案。

我需要在会话被销毁之前从 HttpSessionListener 中的 globalsession 范围 bean 访问信息。

在检查会话属性后,我找到了一种解决方案,但似乎并不顺利:

MyBean myBean = httpSessionEvent.getSession().getAttribute("scopedTarget."+"myBeanImlp");

我也有单例bean,通过target+proxy包含会话bean,但是通过ctx.getBean("mySingletonBean")将它们放入sessionDestroyed,对会话bean的引用在它们内部无效(会话bean在sessionDestroyed调用之前已经被销毁)

有人知道此类问题的良好和适当的解决方案吗?

我在想我们需要像 DestructionAwareBeanPostProcessor 这样的东西,但是对于会话 bean,我可以在其中查看 bean,准备好销毁并采取我需要的操作。

【问题讨论】:

    标签: java spring


    【解决方案1】:

    您可以尝试将会话侦听器定义为组件并注入 ApplicationContext(或所需的 bean),然后访问它。你可以看看How to inject dependencies into HttpSessionListener, using Spring?

    【讨论】:

      猜你喜欢
      • 2013-10-03
      • 2019-07-11
      • 2011-07-11
      • 2013-03-18
      • 2014-08-26
      • 2013-03-02
      • 2011-09-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多