开发者

@PreDestroy never called on @ViewScoped [duplicate]

开发者 https://www.devze.com 2023-03-13 14:03 出处:网络
This question already has answers here: JSF 2.1 ViewScopedBean @PreDestroy method is not called (2 answers)
This question already has answers here: JSF 2.1 ViewScopedBean @PreDestroy method is not called (2 answers) Closed 3 years ago.

I have a @ViewScoped bean that has a method with an @PreDestroy annotation that should make sure some remote connections are closed. However, the method is not called when the user navigates away.

Is there anything one can do wrong? Do I have to register anything anywhere in order to make it work?

It's开发者_StackOverflow中文版 a simple public method (void) that throws no exception.

I'm using JSF 2 (MyFaces) with Tomcat 7.0.12. Could it be a problem with Tomcat?

UPDATE

The @PostConstruct annotation works fine.


This is a known issue and unfortunately not trivial to solve without letting all the navigation take place through the view scoped bean in question. See also JSF-impl issue 1839. This does only not cover cases where the enduser changes the URL in browser address bar or closes the window/tab. Their @PreDestroy will also not be called when the session get destroyed. An enhancement request for the specification has however been posted to get the dangling views to destroy during session destroy anyway: JSF-spec issue 905.

0

精彩评论

暂无评论...
验证码 换一张
取 消