尝试将一个EJB注入另一个EJB后,CreateException和NamingException

时间:2011-12-28 02:36:13

标签: java-ee ejb

我正在使用JEE6和Glassfish 3.1以及Eclipse helios。我一直用数据库运行几个EJB,servlet和JPA。现在我只是尝试创建另一个EJB @Statless和@LocalBean。当我将这个bean注入另一个bean以便我可以从那里调用它时,我会遇到部署错误。

  [#|2011-12-27T19:15:14.703-0700|SEVERE|glassfish3.1.1|javax.enterprise.system.tools.ad    min.org.glassfish.deployment.admin|_ThreadID=19;_ThreadName=Thread-2;|
Exception while loading the app : javax.ejb.CreateException: Initialization      failed for Singleton Driver
javax.ejb.CreateException: Initialization failed for Singleton Driver
    at     com.sun.ejb.containers.AbstractSingletonContainer.createSingletonEJB(AbstractSingletonContainer.java:547)
    at     com.sun.ejb.containers.AbstractSingletonContainer.access$100(AbstractSingletonContainer.java:79)

并且

com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:376)
    at com.sun.ejb.containers.AbstractSingletonContainer.createSingletonEJB(AbstractSingletonContainer.java:538)
    ... 38 more
Caused by: javax.ejb.EJBException: javax.ejb.CreateException: Could not create stateless EJB
    at com.sun.ejb.containers.StatelessSessionContainer$SessionContextFactory.create(StatelessSessionContainer.java:726)
    at com.sun.ejb.containers.util.pool.NonBlockingPool.getObject(NonBlockingPool.java:247)
    at com.sun.ejb.containers.StatelessSessionContainer._getContext(StatelessSessionContainer.java:449)
    ... 63 more
Caused by: javax.ejb.CreateException: Could not create stateless EJB
    at com.sun.ejb.containers.StatelessSessionContainer.createStatelessEJB(StatelessSessionContainer.java:534)
    at com.sun.ejb.containers.StatelessSessionContainer.access$000(StatelessSessionContainer.java:95)

最后:

Caused by: javax.naming.NamingException: Exception resolving Ejb for 'Remote ejb-ref name=com.logic.bean/tclient,Remote 3.x interface =com.thrift.ThriftClient,ejb-link=null,lookup=,mappedName=,jndi-name=com.thrift.ThriftClient,refType=Session' .  Actual (possibly internal) Remote JNDI name used for lookup is 'com.thrift.ThriftClient#com.thrift.ThriftClient' [Root exception is javax.naming.NamingException: Lookup failed for 'com.thrift.ThriftClient#com.thrift.ThriftClient' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: com.thrift.ThriftClient#com.thrift.ThriftClient not found]]
    at com.sun.ejb.EjbNamingReferenceManagerImpl.resolveEjbReference(EjbNamingReferenceManagerImpl.java:178)
    at com.sun.enterprise.container.common.impl.ComponentEnvManagerImpl$EjbReferenceProxy.create(ComponentEnvManagerImpl.java:1106)

这是新的EJB代码:

...imports...
@Stateless
@LocalBean
public class ThriftClient {


public ThriftClient(){}

...other code....

以及我如何注射它:

@EJB ThriftClient tclient;

我将它注入到另一个无状态bean中,该bean具有其他可用的EJB注入。

1 个答案:

答案 0 :(得分:1)

检查Glassfish控制台是否正确部署了bean并使用了什么JNDI名称。我知道它应该开箱即用,但也许值得玩@EJB注释参数使它指向正确的JNDI名称。这可以帮助您找到真正的问题,因为它与JNDI命名明显相关。您也可以尝试通过显式JNDI查找来查找bean而不是注入它,然后您可能会注意到问题。