我试图在以下环境中创建一个企业应用程序(具有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
- Oracle 10 g gh/<>
我已经创建了一个类库(新项目-> 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没有强制要求将远程接口放在单独的类库中。
我有NetBeans IDE 6.9.1仍然安装在我的PC上,我试图创建相同的应用程序(没有单独的类库,远程接口在同一个EJB模块),它按预期工作。
最后一件事:当我从两个模块(EJB和WAR)中删除这个类库并只部署Java EE模块(在NetBeans中用三角形表示的那个模块)时,它执行预期的功能,从数据库中检索数据并在JSF页面上显示。
所以,我对这个异常的原因感到非常困惑,不能肯定地说它是否因为类库问题或其他必要的配置,我可能会丢失(虽然推测,可能有一些JNDI查找问题,我不知道)。
如果有人有一个关于如何在NetBeans 7中创建企业web应用程序的链接。
代码中的一个错误是在@Remote注释中有一个类名。我很好奇,你为什么觉得有必要把它放在那里?
在任何长度,它不应该在那里,当@Remote是用来标记远程接口的,一定要删除。
另外,当在同一个JVM中注入时,您应该使用@Local接口或根本不使用接口(具有本地语义)。也就是说,每次调用该方法并返回一些东西时,您现在都在封送(序列化/深度复制)返回值。如果这些语义是不需要的,这是相当浪费。