How does Spring know when to call ‘destory’ method on a session/request scoped bean (in other words, how does it detect that the concerned bean is going out of scope)?
I read somewhere that it uses request/session listeners to be notified of these events. But these listners need to be defined in web.xml, and there’s no mention of defining such listeners in Spring literature. So how does this work?
The
org.springframework.web.servlet.DispatcherServletdoes it. It uses own code, e.g. theorg.springframework.web.context.request.RequestAttributes#registerDestructionCallbackcallback list functionality to register all these scoped beans.