如何在PhaseListener中调用EJB [英] How to call EJB in PhaseListener
问题描述
我使用JSF 2和EJB 3.1,它们都部署在Glassfish 3.1上。
I use JSF 2 and EJB 3.1, all of them are deployed on Glassfish 3.1.
当我设置一个名为MyInterceptor的类时,它实现了PhaseListener,我不能撤销其中的远程EJB接口。
When i setup a class named MyInterceptor which is implemented PhaseListener, i can not revoke remote EJB interface inside it.
它注意到NullPointerException ...
It notice "NullPointerException ..."
public class MyInterceptor implements PhaseListener {
@EJB(name="AuthorizationEJB",
beanInterface=AuthorizationService.class,
mappedName="corbaname:iiop:localhost:3700#ejb/AuthorizationEJB")
public AuthorizationService authorizationService;
....
}
当我调用authorizationService.dosomestuff()时,它会引发错误NullPointerException
When I call authorizationService.dosomestuff(), it raise error NullPointerException
我该如何解决?
提前感谢
推荐答案
在JSF 2.1及更早版本中,PhaseListeners不幸没有注入目标(意味着您不能使用注入他们)。您可以通过JNDI以编程方式执行查找。
In JSF 2.1 and earlier, PhaseListeners are unfortunately no injection targets (meaning you can't use injection in them). You can do your lookup programmatically via JNDI instead though.
在JSF 2.2中,所有JSF工件(包括PhaseListeners)都将是注入目标,但这可能无法帮助您。
In JSF 2.2 all JSF artifacts (including PhaseListeners) will be injection targets, but this will probably not help you now.
与您的问题无关,但我不知道您要通过指定 beanInterface
在您的注释。很可能你也不需要名称
属性,如果你的bean是本地bean,你也不需要 mappedName
。
Unrelated to your question, but I'm not sure what you're trying to achieve by specifying the beanInterface
in your annotation. Most likely you'll also don't need the name
attribute and if your bean is a local bean you'll also don't need mappedName
.
这篇关于如何在PhaseListener中调用EJB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!