jjzjj

sessionContext

全部标签

java - sessionContext.getCallerPrincipal() 中的 NullPointerException

我有一个简单的(webprofile)EJB3.1应用程序并尝试确定@ApplicationScopedCDIBean中的当前用户,所以我使用:PrincipalcallerPrincipal=this.sessionContext.getCallerPrincipal()工作正常(因此我可以确定当前用户的名称)。但是在任何(其他)EJB出现任何异常之后,此调用将不再起作用(我需要重新启动服务器)!该方法没有返回调用方主体,而是抛出此异常。Causedby:java.lang.NullPointerExceptionatcom.sun.ejb.containers.EJBContext

java - SessionContext.getBusinessObject() 的返回值与 bean 中使用的 'this' 关键字有何不同?

SessionContext.getBusinessObject()在文档中描述如下,Obtainanobjectthatcanbeusedtoinvokethecurrentbeanthroughthegivenbusinessinterface.Parameters:businessInterface-Oneofthelocalbusinessinterfacesorremotebusinessinterfacesforthissessionbean.Returns:Thebusinessobjectcorrespondingtothegivenbusinessinterface.