@PostConstruct 不要调用会话托管 bean
正如我在标题中所说,我在会话范围内的托管 bean 中有一个带有 @PostConstruct
标记的方法。但该方法从未被调用。在视图范围内的另一个 bean 中,@PostConstruct 工作正常。 @Postconstruct
标签在会话 bean 中工作吗? 这基本上就是我的问题。 再见,谢谢!
Like I say in the title, I have a method with the @PostConstruct
tag in a managed bean in session scope. But the method is never called. In another bean in view scope the @PostConstruct
works fine.
The @Postconstruct
tag work in a session bean?
That's basically my question.
Bye and thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
确保您的 bean 或您的 bean 的前身中的任何其他方法上都没有 @PostConstruct。
对于托管 Bean,仅允许有一个 @PostConstruct。
Make sure you don't have a @PostConstruct on any other method in your bean or your bean's predecessor.
There is only one @PostConstruct allowed for a managed bean.
我也面临着同样的问题。当我从会话中销毁 bean 时,问题得到解决(如果 bean 在会话范围内,则它适用于请求范围)。
当bean位于会话范围内时,带有@PostConstruct注释的方法永远不会被调用两次,因为bean已经被实例化并存储在会话中。
I was also facing the same issue. The issue get resolved when I destroy the bean from the session(if the bean is in the session scope, it works fine for request scope).
When the bean is in the session scope, the method with the @PostConstruct annotation will never be called twice, as the bean has already been instantiated and is stored in the session.
你如何引用会话 bean?也许该 bean 尚未实例化,您是否还在托管 bean 的构造函数中进行了一些日志记录?
How do you refer the session bean? Maybe the bean was not instantiated yet, do you also have some logging in the constructor of the managed bean?
要么你没有编译和部署带有更改的 bean 类,要么你有另一个副本具有相同名称但位于不同包中的 bean,而该包实际上已被使用。
验证所有内容,清理所有内容并进行完整重建/重新部署/重新启动。
Either you have not compiled and deployed the bean class with the changes, or you have another copy of the bean with the same name but in a different package which in turn is actually been used instead.
Verify everything, cleanup everything and do a full rebuild/redeploy/restart.