@PreDestroy 从未调用过@ViewScoped [英] @PreDestroy never called on @ViewScoped

查看:35
本文介绍了@PreDestroy 从未调用过@ViewScoped的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 @ViewScoped bean,它有一个带有 @PreDestroy 注释的方法,它应该确保关闭一些远程连接.但是,当用户离开时不会调用该方法.

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?

这是一个不抛出异常的简单公共方法(void).

It's a simple public method (void) that throws no exception.

我将 JSF 2 (MyFaces) 与 Tomcat 7.0.12 一起使用.会不会是Tomcat的问题?

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

更新

@PostConstruct 注释工作正常.

推荐答案

这是一个已知问题,不幸的是,如果不让所有导航都通过相关的视图作用域 bean 进行,解决起来并不容易.另请参阅 JSF-impl 问题 1839.这仅不包括最终用户更改浏览器地址栏中的 URL 或关闭窗口/选项卡的情况.当会话被销毁时,它们的 @PreDestroy 也不会被调用.然而,已经发布了对该规范的增强请求,以在会话销毁期间销毁悬空视图:JSF 规范问题 905.

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.

这篇关于@PreDestroy 从未调用过@ViewScoped的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆