@PreDestroy not called in Spring bean session for tomcat disconnect session

Using Spring 3.0.5 GA

Use the @PreDestroy method to use a bean for the session. They just noticed that if the ownership of the HttpSession expires (i.e., exceeds the Servlet Container session time), then the @PreDestroy callback is issued. However, if I just turn off the application server, @PreDestroy is NOT called. Is it design or bug? If last, any suggestions on a workaround?

FWIW, @PreDestroy on singleton beans is called in both cases.

Thanks, -nikita p>

PS. There is a possible Spring related bug - SPR-7359

+6
spring tomcat session
source share
2 answers

Interesting. Session beans has its own @Predestroy , called when a session close event occurs. If the container never dispatches this event, then Spring will not be informed. I'm not sure if this is a bug or not, and if so, then this is a bug in Spring or Tomcat. The latter seems more likely, but I don't know if the Servlet container should do this.

If this is a show stopper for you, you may want to register a registered bean with a single "registrar" @PostConstruct during its @PostConstruct and unregister it with @Predestroy . If the logger is turned off, it can propagate this event to all beans remaining in the session that are still registered with it.

Not an ideal, but a pragmatic solution.

+6
source share

I would suggest that this is by design.

Tomcat, for example, saves its sessions in SESSIONS.ser by default for each deployed application. If you close Tomcat and restart it, it re-reads SESSIONS.ser. So, I would suggest that with respect to Spring, closing the container does not necessarily mean ending the session - so @PreDestroy does not invoke beans in the session.

+2
source share

All Articles