Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-9672

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

    Details

    • Type: Bug
    • Status: Open
    • Priority: 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.

        Attachments

          Activity

            People

            • Assignee:
              juergen.hoeller Juergen Hoeller
              Reporter:
              sebpaul Sebastian Paul
              Last updater:
              Andreas Höhmann
            • Votes:
              2 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Days since last comment:
                4 years, 4 weeks ago