ejbFacade is null

心已入冬 提交于 2019-12-01 23:07:22

@EJBs 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:

overzichtAlle.setEjbFacade(ejbFacade);
OverzichtAlle overzichtAlle = new OverzichtAlle();

Instead, the following is happening behind the scenes:

OverzichtAlle overzichtAlle = new OverzichtAlle();
overzichtAlle.setEjbFacade(ejbFacade);

So the ejbFacade is not available inside bean's constructor. The normal approach is to use a @PostConstruct method for this.

@PostConstruct
public void init() {
    projE = ejbFacade.findAll();
    omvormenProjectTypes();
}

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:

OverzichtAlle overzichtAlle = new OverzichtAlle();
overzichtAlle.setEjbFacade(ejbFacade);
overzichtAlle.init();

Note that the method name doesn't matter. But init() is pretty self-documenting.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!