javax.naming.NameNotFoundException:admin.sessionbeans.AdminSessionBeanRemote#admin.sessionbeans.AdminSessionBeanRemote not found

时间:2013-02-26 03:16:10

标签: jsf java-ee jsf-2 jpa-2.0 ejb-3.1

我正在尝试在以下环境(具有Java EE,EJB和WAR模块的环境)中创建企业应用程序。我正在遵循these指令(虽然不是关于Web应用程序,但我找不到任何关于Web应用程序的文章)。

  • NetBeans 7.2.1
  • Glassfish Server 3.1.2(包含Servlet 3.0 API)
  • EJB 3.1
  • JPA 2.0
  • JSF 2.1
  • Oracle 10g

我创建了一个类库(New Project - > Java - > Java类库)来放置由无状态会话bean实现的远程(javax.ejb.Remote)接口。类库已添加到两个模块(EJB和WAR)的类路径中。

尝试运行此应用程序时,会导致以下异常。

com.sun.faces.mgbean.ManagedBeanCreationException: An error occurred performing resource injection on managed bean transporterBean
        at com.sun.faces.mgbean.BeanBuilder.injectResources(BeanBuilder.java:211)
        at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:103)
        at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
        at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
        at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
        at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
        at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
        at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
        at com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:103)
        at com.sun.el.parser.AstValue.getValue(AstValue.java:179)
        at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:224)
        at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
        at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
        at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
        at javax.faces.component.UIData.getValue(UIData.java:731)
        at javax.faces.component.UIData.getDataModel(UIData.java:1798)
        at javax.faces.component.UIData.setRowIndexWithoutRowStatePreserved(UIData.java:484)
        at javax.faces.component.UIData.setRowIndex(UIData.java:473)
        at com.sun.faces.renderkit.html_basic.TableRenderer.encodeBegin(TableRenderer.java:81)
        at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:820)
        at javax.faces.component.UIData.encodeBegin(UIData.java:1118)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1755)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
        at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:402)
        at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
        at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
        at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
        at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
        at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
        at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
        at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
        at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
        at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
        at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
        at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
        at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
        at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
        at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
        at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
        at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
        at java.lang.Thread.run(Thread.java:722)
Caused by: com.sun.faces.spi.InjectionProviderException: com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting to inject Remote ejb-ref name=managedbeans.TransporterBean/adminSessionBeanRemote,Remote 3.x interface =admin.sessionbeans.AdminSessionBeanRemote,ejb-link=null,lookup=,mappedName=,jndi-name=admin.sessionbeans.AdminSessionBeanRemote,refType=Session into class managedbeans.TransporterBean: Lookup failed for 'java:comp/env/managedbeans.TransporterBean/adminSessionBeanRemote' 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 org.glassfish.faces.integration.GlassFishInjectionProvider.inject(GlassFishInjectionProvider.java:194)
        at com.sun.faces.mgbean.BeanBuilder.injectResources(BeanBuilder.java:205)
        ... 53 more
Caused by: com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting to inject Remote ejb-ref name=managedbeans.TransporterBean/adminSessionBeanRemote,Remote 3.x interface =admin.sessionbeans.AdminSessionBeanRemote,ejb-link=null,lookup=,mappedName=,jndi-name=admin.sessionbeans.AdminSessionBeanRemote,refType=Session into class managedbeans.TransporterBean: Lookup failed for 'java:comp/env/managedbeans.TransporterBean/adminSessionBeanRemote' 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:703)
        at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.inject(InjectionManagerImpl.java:470)
        at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.injectInstance(InjectionManagerImpl.java:171)
        at org.glassfish.faces.integration.GlassFishInjectionProvider.inject(GlassFishInjectionProvider.java:184)
        ... 54 more
Caused by: javax.naming.NamingException: Lookup failed for 'java:comp/env/managedbeans.TransporterBean/adminSessionBeanRemote' 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=managedbeans.TransporterBean/adminSessionBeanRemote,Remote 3.x interface =admin.sessionbeans.AdminSessionBeanRemote,ejb-link=null,lookup=,mappedName=,jndi-name=admin.sessionbeans.AdminSessionBeanRemote,refType=Session' .  Actual (possibly internal) Remote JNDI name used for lookup is 'admin.sessionbeans.AdminSessionBeanRemote#admin.sessionbeans.AdminSessionBeanRemote' [Root exception is javax.naming.NamingException: Lookup failed for 'admin.sessionbeans.AdminSessionBeanRemote#admin.sessionbeans.AdminSessionBeanRemote' 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: admin.sessionbeans.AdminSessionBeanRemote#admin.sessionbeans.AdminSessionBeanRemote not found]]]
        at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:518)
        at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
        at javax.naming.InitialContext.lookup(InitialContext.java:411)
        at javax.naming.InitialContext.lookup(InitialContext.java:411)
        at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:599)
        ... 57 more
Caused by: javax.naming.NamingException: Exception resolving Ejb for 'Remote ejb-ref name=managedbeans.TransporterBean/adminSessionBeanRemote,Remote 3.x interface =admin.sessionbeans.AdminSessionBeanRemote,ejb-link=null,lookup=,mappedName=,jndi-name=admin.sessionbeans.AdminSessionBeanRemote,refType=Session' .  Actual (possibly internal) Remote JNDI name used for lookup is 'admin.sessionbeans.AdminSessionBeanRemote#admin.sessionbeans.AdminSessionBeanRemote' [Root exception is javax.naming.NamingException: Lookup failed for 'admin.sessionbeans.AdminSessionBeanRemote#admin.sessionbeans.AdminSessionBeanRemote' 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: admin.sessionbeans.AdminSessionBeanRemote#admin.sessionbeans.AdminSessionBeanRemote not found]]
        at com.sun.ejb.EjbNamingReferenceManagerImpl.resolveEjbReference(EjbNamingReferenceManagerImpl.java:191)
        at com.sun.enterprise.container.common.impl.ComponentEnvManagerImpl$EjbReferenceProxy.create(ComponentEnvManagerImpl.java:1109)
        at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:776)
        at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:744)
        at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:169)
        at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:498)
        ... 61 more
Caused by: javax.naming.NamingException: Lookup failed for 'admin.sessionbeans.AdminSessionBeanRemote#admin.sessionbeans.AdminSessionBeanRemote' 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: admin.sessionbeans.AdminSessionBeanRemote#admin.sessionbeans.AdminSessionBeanRemote not found]
        at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:518)
        at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
        at javax.naming.InitialContext.lookup(InitialContext.java:411)
        at javax.naming.InitialContext.lookup(InitialContext.java:411)
        at com.sun.ejb.EjbNamingReferenceManagerImpl.resolveEjbReference(EjbNamingReferenceManagerImpl.java:186)
        ... 66 more
Caused by: javax.naming.NameNotFoundException: admin.sessionbeans.AdminSessionBeanRemote#admin.sessionbeans.AdminSessionBeanRemote not found
        at com.sun.enterprise.naming.impl.TransientContext.doLookup(TransientContext.java:248)
        at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:215)
        at com.sun.enterprise.naming.impl.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:77)
        at com.sun.enterprise.naming.impl.LocalSerialContextProviderImpl.lookup(LocalSerialContextProviderImpl.java:119)
        at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:505)
        ... 70 more

远程接口如下。

 package admin.sessionbeans;

import entities.Transporter;
import java.util.List;
import javax.ejb.Remote;

@Remote(AdminSessionBeanRemote.class)
public interface AdminSessionBeanRemote 
{
    public List<Transporter> getAllTransporters(); 
}

无状态会话bean。

package admin.sessionbeans;

import entities.Transporter;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Stateless//(mappedName="adminSessionBean")
public class AdminSessionBean implements AdminSessionBeanRemote {

    @PersistenceContext(unitName="wagafashion-ejbPU")
    private EntityManager entityManager;

    @Override
    public List<Transporter> getAllTransporters() 
    {
        return entityManager.createNamedQuery("Transporter.findAll").getResultList();
    }
}

JSF托管bean。

package managedbeans;

import admin.sessionbeans.AdminSessionBeanRemote;
import entities.Transporter;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

@ManagedBean
@RequestScoped
public final class TransporterBean 
{
    @EJB
    private AdminSessionBeanRemote adminSessionBeanRemote;
    private List<Transporter>transporters;

    public TransporterBean() 
    {

    }

    public List<Transporter> getTransporters()
    {
        transporters=adminSessionBeanRemote.getAllTransporters();
        return transporters;
    }

    public void setTransporters(List<Transporter> transporters) 
    {
        this.transporters = transporters;
    }
}

我已根据this comment将所有实体类添加到类库中。

  

客户端jar应包含远程接口和任何类   这些接口取决于


大约一年前,当我使用NetBeans 6.9.1时,我开发了一些这样的应用程序。该版本的IDE不要求将远程接口放在单独的类库中。

我的PC上仍然安装了NetBeans IDE 6.9.1,并且我尝试创建相同的应用程序(没有单独的类库,远程接口在同一个EJB模块中)并且它按预期工作。

最后一件事:当我从两个模块(EJB和WAR)中删除此类库并仅部署Java EE模块(在NetBeans中用三角形表示的模块)时,它会执行其预期的功能,检索数据从数据库中显示并显示在JSF页面上。

所以,我对这个异常的原因非常困惑,并且不能肯定地说是否是因为类库问题或者我可能会丢失的其他必需配置(尽管可能会有一些JNDI查找我不知道的问题。)


如果某人有关于如何在NetBeans 7.x中创建企业Web应用程序的链接,那么它将非常有用。

1 个答案:

答案 0 :(得分:1)

您的代码有一个问题是在@Remote注释中有一个类名。我很好奇,为什么你觉得有必要把它放在那里?

任何时候都不应该在那里 @Remote用于标记远程接口,绝对应该删除。

此外,在同一JVM中注入时,您应该使用@Local接口或根本不使用任何接口(具有本地语义)。也就是说,每次调用方法并返回一些内容时,您现在正在编组(序列化/深度复制)返回值。如果不需要这些语义,那就太浪费了。