Spring Framework
  1. Spring Framework
  2. SPR-9672

Destroy method of session scoped bean cannot access other session scoped bean

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 3.1.2
    • Fix Version/s: Waiting for Triage
    • Component/s: Core:DI
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      Destroy method of session scoped bean cannot access other session scoped bean:

      CommonAnnotationBeanPostProcessor - postProcessBeforeDestruction - Invocation of destroy method failed on bean with name 'scopedTarget.applicationManagerImpl': org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.localizationManagerImpl': Scope 'session' is not active for the current thread;
      ...

      In my concrete case, applicationManagerImpl tries to remove an event listener from localizationManagerImpl. Of course, he only knows about the interface, so he is not aware of the fact that localizationManagerImpl is also session scoped (deregistration of listener is not really necessary).

      The problem is caused by the missing HttpServletRequest, which usually carries the session. When sessions expire, no request is active, so the RequestContextHolder has no RequestAttributes

      at org.springframework.web.context.request.DestructionCallbackBindingListener.valueUnbound(DestructionCallbackBindingListener.java:51) [spring-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
      at org.apache.catalina.session.StandardSession.removeAttributeInternal(StandardSession.java:1710) [catalina.jar:6.0.35.B]
      at org.apache.catalina.session.StandardSession.expire(StandardSession.java:812) [catalina.jar:6.0.35.B]
      at org.apache.catalina.session.StandardSession.isValid(StandardSession.java:587) [catalina.jar:6.0.35.B]
      at org.apache.catalina.session.ManagerBase.processExpires(ManagerBase.java:714) [catalina.jar:6.0.35.B]
      at org.apache.catalina.session.ManagerBase.backgroundProcess(ManagerBase.java:699) [catalina.jar:6.0.35.B]
      at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1368) [catalina.jar:6.0.35.B]
      at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1653) [catalina.jar:6.0.35.B]
      at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1662) [catalina.jar:6.0.35.B]
      at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1662) [catalina.jar:6.0.35.B]
      at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1642) [catalina.jar:6.0.35.B]

      Spring should handle this by setting up a RequestAttributes instance which carries the session which is passed to org.springframework.web.context.request.DestructionCallbackBindingListener.valueUnbound(HttpSessionBindingEvent)
      Then, referencing session scoped dependencies should still be possible.

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Unassigned
            Reporter:
            Sebastian Paul
            Last updater:
            Chris Beams
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Days since last comment:
              1 year, 37 weeks, 2 days ago