1

我正在尝试在以下环境中创建一个企业应用程序(具有 Java EE、EJB 和 WAR 模块的环境)。我正在遵循这些说明(虽然这些说明与 Web 应用程序无关,但我找不到任何关于 Web 应用程序的文章)。

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

我创建了一个类库(新项目 -> Java -> Java 类库)来放置javax.ejb.Remote将由无状态会话 bean 实现的远程()接口。类库已添加到两个模块(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;
    }
}

我已根据此注释将所有实体类添加到类库中。

客户端 jar 应包含远程接口以及这些接口所依赖的任何类


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

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

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

所以,我对这个异常的原因非常困惑,不能确定是因为类库问题还是我可能缺少的其他必需配置(尽管可能有一些 JNDI 查找我不知道的问题)。


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

4

1 回答 1

2

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

无论如何,当@Remote 用于标记远程接口时,它不应该存在,并且绝对应该被删除。

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

于 2013-02-26T09:37:56.420 回答