ejbFacade 为空
我从 jsf 页面 overzichtAlleGroepen.xhtml 调用 ManagedBean OverzichtAlle.java
但是当我进入此页面时,我收到错误消息 Can't instantiate ManagedBeans.OverzichtAlle due to a NullpointerException...
当我调试时,我看到我的 ejbFacade 为 null ..
这是 EJB
@EJB private ProjecttypeEFacade ejbFacade;
,这是我的构造函数:
public OverzichtAlle()
{
projE = ejbFacade.findAll();
omvormenProjectTypes();
}
projE 是一个列表(实体列表)
我做错了什么?
I call the managedBean OverzichtAlle.java from the jsf page overzichtAlleGroepen.xhtml
But when I get on this page i get the errormessage can't instantiate managedBeans.OverzichtAlle due to a Nullpointerexception...
When I debug, I see that my ejbFacade is null..
this is the EJB
@EJB private ProjecttypeEFacade ejbFacade;
and this is my constructor:
public OverzichtAlle()
{
projE = ejbFacade.findAll();
omvormenProjectTypes();
}
projE is a List (entity-list)
What am i doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
@EJB
在 bean 构造之后注入。对于 EJB 注入管理器来说,在构造 bean setter 方法之前不可能调用它:相反,在幕后发生以下情况:
因此
ejbFacade
在内部不可用bean 的构造函数。正常的方法是使用@PostConstruct
方法。@PostConstruct
方法在 bean 构造以及所有托管属性和依赖项注入之后直接调用。您可以在那里完成依赖于 EJB 的初始化工作。然后将在幕后发生以下情况:请注意,方法名称并不重要。但是
init()
是非常自文档化的。@EJB
s are injected after bean's construction. It's for the EJB injection manager namely not possible to call a bean setter method before constructing it:Instead, the following is happening behind the scenes:
So the
ejbFacade
is not available inside bean's constructor. The normal approach is to use a@PostConstruct
method for this.A
@PostConstruct
method is called directly after bean's construction and all managed property and dependency injections. You can do your EJB-dependent initializing job in there. The following will then happen behind the scenes:Note that the method name doesn't matter. But
init()
is pretty self-documenting.