@PreDestroy 从未调用过 @ViewScoped
我有一个 @ViewScoped bean,它有一个带有 @PreDestroy 注释的方法,该注释应确保关闭一些远程连接。但是,当用户离开时,不会调用该方法。
人有可能做错什么吗?我是否必须在任何地方注册任何东西才能使其正常工作?
这是一个不抛出异常的简单公共方法 (void
)。
我正在使用 JSF 2 (MyFaces) 和 Tomcat 7.0.12。会不会是Tomcat的问题?
更新
@PostConstruct
注释工作正常。
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 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个已知问题,不幸的是,如果不让所有导航都通过相关视图作用域 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.