问题描述
我无法在EJB上获取SessionContext对象。我已经尝试了所有在,而且它们都没有工作。例如,我的项目中的以下代码...
@Stateful
public class SecurityService {
@Resource
private SessionContext context;
@PostConstruct
public void init(){
}
}
...在部署期间生成以下异常:
[#| 2012-02- 28T14:35:02.805-0300 |严重| glassfish3.1.1 | javax.enterprise.system.core.com.sun.enterprise.v3.server | _ThreadID = 18; _ThreadName =管理线程池-4848(5); |日志消息为空。
java.lang.NullPointerException
在com.sun.appserv.connectors.internal.api.AppSpecificConnectorClassLoaderUtil.detectResourceInRA(AppSpecificConnectorClassLoaderUtil.java:266)
在com.sun.appserv.connectors.internal .app.appSpecificConnectorClassLoaderUtil.processDescriptorForRAReferences .connectors.internal.api.AppSpecificConnectorClassLoaderUtil.detectReferredRARs(AppSpecificConnectorClassLoaderUtil.java:118)
在com.sun.appserv.connectors.internal.api.ConnectorClassLoaderServiceImpl.getConnectorClassLoader(ConnectorClassLoaderServiceImpl.java:111)
at com .sun.enterprise.v3.server.ClassLoaderHierarchyImpl.getConnectorClassLoader(ClassLoaderHierarchyImpl.java:117)
如果我去除@Resource注释它部署,但不起作用(我已经尝试使用JNDI和以前引用的其他方法)。
我使用的是Glassfish 3.1.1,我的项目是与CDI和EJB本地的JSF与JPA的服务。我已经尝试在CDI bean上注入SessionContext,但是收到相同的错误。我的EJB配置了注释,而我的beans.xml没有配置(但存在)。
一个奇怪的事情是,使用JNDI查找我已经设法得到一个类型为SessionContextImpl的对象在路径java上:/comp / EJBContext on @PostConstruct init()方法。但是,一旦调用另一个EJB方法(?),它就变为null,并且它不包含用户的角色数据(对isCallerInRole()的调用抛出异常)。此外,它不是一个EJBContext对象。
我正在使用Maven打包WAR中的所有内容,并且Java EE的依赖性标记为提供,如下所示:
<依赖关系>
< groupId> javax< / groupId>
< artifactId> javaee-web-api< / artifactId>
< version> 6.0< / version>
< scope>已提供< / scope>
< / dependency>
在我看来,容器中没有提供SessionContext(EJBCOntext)我不知道即使这是可能的,我不知道如何解决这个问题。
如果您对此有任何想法,我很乐意听到。谢谢。
嗯,我升级到了Glassfish 3.1.2,问题解决了。现在我可以按照预期注入 javax.ejb.SessionContext
。
特别感谢@perissf的帮助。 / p>
I can't get a SessionContext object on an EJB. I've tried all the options suggested on 4 Ways to Get EJBContext in EJB 3 and none of them worked. For example, the following code in my project...
@Stateful
public class SecurityService {
@Resource
private SessionContext context;
@PostConstruct
public void init() {
}
}
... generates the following exception during deploy:
[#|2012-02-28T14:35:02.805-0300|SEVERE|glassfish3.1.1|javax.enterprise.system.core.com.sun.enterprise.v3.server|_ThreadID=18;_ThreadName=admin-thread-pool-4848(5);|The log message is null.
java.lang.NullPointerException
at com.sun.appserv.connectors.internal.api.AppSpecificConnectorClassLoaderUtil.detectResourceInRA(AppSpecificConnectorClassLoaderUtil.java:266)
at com.sun.appserv.connectors.internal.api.AppSpecificConnectorClassLoaderUtil.processDescriptorForRAReferences(AppSpecificConnectorClassLoaderUtil.java:211)
at com.sun.appserv.connectors.internal.api.AppSpecificConnectorClassLoaderUtil.processDescriptorForRAReferences(AppSpecificConnectorClassLoaderUtil.java:130)
at com.sun.appserv.connectors.internal.api.AppSpecificConnectorClassLoaderUtil.detectReferredRARs(AppSpecificConnectorClassLoaderUtil.java:118)
at com.sun.appserv.connectors.internal.api.ConnectorClassLoaderServiceImpl.getConnectorClassLoader(ConnectorClassLoaderServiceImpl.java:111)
at com.sun.enterprise.v3.server.ClassLoaderHierarchyImpl.getConnectorClassLoader(ClassLoaderHierarchyImpl.java:117)
If I remove the @Resource annotation it deploys, but does not work (i've tried with JNDI and the other methods cited before).
I'm using Glassfish 3.1.1, and my project is JSF with CDI and EJB locally to services with JPA. I've tried injecting SessionContext on CDI beans but received the same errors. My EJB are configured with annotations, and my beans.xml have no configurations (but exists).
One strange thing is that with JNDI lookup I've managed to get an object of type SessionContextImpl on path java:/comp/EJBContext on the @PostConstruct init() method. BUT, it goes to null as soon as another EJB method is called (?) and it does not contain user's roles data (a call to isCallerInRole() throws an exception). Also, it is not an EJBContext object.
I'm packaging everything in a WAR using Maven, and the dependency of Java EE is marked as provided, as the following shows:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
It seems to me that there is no SessionContext (EJBCOntext) been provided by the container at all. I don't know even if that is possible, and I have no idea on how to solve this.
Please, If you have ANY idea about this, I'll be glad to hear it. Thank you.
Well, I've upgraded to Glassfish 3.1.2 and the problem was solved. Now I can inject javax.ejb.SessionContext
as expected.
Special thanks to @perissf for the help.
这篇关于无法在EJB上获取SessionContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!