javax.naming.NameNotFoundException:com.dao.implementation.EmployeeDAOImpl#com.dao.implementation.EmployeeDAOImpl not found

时间:2015-10-26 22:25:28

标签: java-ee ejb cdi

我有一个EJB

@Named("employeeController")
@RequestScoped
public class EmployeeController {

    @EJB
    private EmployeeDAOImpl emDAO;
}

我试图将其注入CDI托管bean中,如下所示:

Caused by: com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting to inject Remote ejb-ref name=com.controllers.EmployeeController/emDAO,Remote 3.x interface =com.dao.implementation.EmployeeDAOImpl,ejb-link=null,lookup=,mappedName=,jndi-name=com.dao.implementation.EmployeeDAOImpl,refType=Session into class com.controllers.EmployeeController: Lookup failed for 'java:comp/env/com.controllers.EmployeeController/emDAO' 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}
    at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:740)
    at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.inject(InjectionManagerImpl.java:507)
    at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.injectInstance(InjectionManagerImpl.java:170)
    at org.glassfish.weld.services.InjectionServicesImpl.aroundInject(InjectionServicesImpl.java:165)
    ... 65 more
Caused by: javax.naming.NamingException: Lookup failed for 'java:comp/env/com.controllers.EmployeeController/emDAO' 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.NamingException: Exception resolving Ejb for 'Remote ejb-ref name=com.controllers.EmployeeController/emDAO,Remote 3.x interface =com.dao.implementation.EmployeeDAOImpl,ejb-link=null,lookup=,mappedName=,jndi-name=com.dao.implementation.EmployeeDAOImpl,refType=Session' .  Actual (possibly internal) Remote JNDI name used for lookup is 'com.dao.implementation.EmployeeDAOImpl#com.dao.implementation.EmployeeDAOImpl' [Root exception is javax.naming.NamingException: Lookup failed for 'com.dao.implementation.EmployeeDAOImpl#com.dao.implementation.EmployeeDAOImpl' 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.dao.implementation.EmployeeDAOImpl#com.dao.implementation.EmployeeDAOImpl not found]]]
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:491)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:438)
    at javax.naming.InitialContext.lookup(InitialContext.java:417)
    at javax.naming.InitialContext.lookup(InitialContext.java:417)
    at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:636)
    ... 68 more
Caused by: javax.naming.NamingException: Exception resolving Ejb for 'Remote ejb-ref name=com.controllers.EmployeeController/emDAO,Remote 3.x interface =com.dao.implementation.EmployeeDAOImpl,ejb-link=null,lookup=,mappedName=,jndi-name=com.dao.implementation.EmployeeDAOImpl,refType=Session' .  Actual (possibly internal) Remote JNDI name used for lookup is 'com.dao.implementation.EmployeeDAOImpl#com.dao.implementation.EmployeeDAOImpl' [Root exception is javax.naming.NamingException: Lookup failed for 'com.dao.implementation.EmployeeDAOImpl#com.dao.implementation.EmployeeDAOImpl' 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.dao.implementation.EmployeeDAOImpl#com.dao.implementation.EmployeeDAOImpl not found]]
    at com.sun.ejb.EjbNamingReferenceManagerImpl.resolveEjbReference(EjbNamingReferenceManagerImpl.java:188)
    at com.sun.enterprise.container.common.impl.ComponentEnvManagerImpl$EjbReferenceProxy.create(ComponentEnvManagerImpl.java:1015)
    at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:745)
    at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:715)
    at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:159)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:471)
    ... 72 more
Caused by: javax.naming.NamingException: Lookup failed for 'com.dao.implementation.EmployeeDAOImpl#com.dao.implementation.EmployeeDAOImpl' 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.dao.implementation.EmployeeDAOImpl#com.dao.implementation.EmployeeDAOImpl not found]
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:491)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:438)
    at javax.naming.InitialContext.lookup(InitialContext.java:417)
    at javax.naming.InitialContext.lookup(InitialContext.java:417)
    at com.sun.ejb.EjbNamingReferenceManagerImpl.resolveEjbReference(EjbNamingReferenceManagerImpl.java:183)
    ... 77 more
Caused by: javax.naming.NameNotFoundException: com.dao.implementation.EmployeeDAOImpl#com.dao.implementation.EmployeeDAOImpl not found
    at com.sun.enterprise.naming.impl.TransientContext.doLookup(TransientContext.java:237)
    at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:204)
    at com.sun.enterprise.naming.impl.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:66)
    at com.sun.enterprise.naming.impl.LocalSerialContextProviderImpl.lookup(LocalSerialContextProviderImpl.java:114)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:478)
    ... 81 more

但是,它会抛出以下异常:

$t0

这是如何引起的?如何解决?

1 个答案:

答案 0 :(得分:1)

而不是在EJB中注入@EJB实现注入其接口EmployeeDAO