Description

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.