我使用Eclipse Indigo来开发使用Glassfish 3 Open Source的JSF 2项目,这在我的计算机中,然后在我的EC2实例中,在Amazon AWS中,对于Glassfish,我创建了一个JDBC连接池,用于我的JPA实体经理。
本地我的项目工作得很好,但是当我部署项目并尝试执行相同的表单时,它会从运行GlassFIsh的同一实例EC2中运行的数据库获取一些值。
我收到此消息:
serverError:class javax.faces.el.EvaluationException
我在搜索它,但到目前为止我找不到任何东西。
我有什么配置可以帮助它吗?
修改
这是堆栈跟踪:
javax.faces.FacesException: #{reportc.generateReport}: javax.ejb.EJBException
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
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 com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
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:636)
Caused by: javax.faces.el.EvaluationException: javax.ejb.EJBException
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
... 32 more
Caused by: javax.ejb.EJBException
at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5193)
at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5091)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4879)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2039)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1990)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:222)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
at $Proxy225.listLastMinutes(Unknown Source)
at com.brainset.eao.__EJB31_Generated__LogEAO__Intf____Bean__.listLastMinutes(Unknown Source)
at com.brainset.controller.ReportControl.getLog(ReportControl.java:234)
at com.brainset.controller.ReportControl.generateReport(ReportControl.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at com.sun.el.parser.AstValue.invoke(AstValue.java:234)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
... 33 more
Caused by: java.lang.IllegalStateException: Attempting to execute an operation on a closed EntityManagerFactory.
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.verifyOpen(EntityManagerFactoryDelegate.java:305)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:276)
编辑2: 这就是我使用EntityManager的方式:
@Stateless(mappedName = "logEAO")
@LocalBean
public class LogEAO {
@PersistenceContext
private EntityManager em;
public LogEAO() {}
public Log find(int id) {
return em.find(Log.class, id);
}
// ..
答案 0 :(得分:18)
如果您正在使用Glassfish服务器,请重新启动服务器为我完成。
答案 1 :(得分:8)
来自你的堆栈跟踪:
引起:java.lang.IllegalStateException:试图对已关闭的EntityManagerFactory执行操作。
您的EJB代码看起来很好。这更像是Glassfish错误或配置错误:
这只能意味着您手动管理 EntityManagerFactory
(和EntityManager
)而不是让容器只通过@PersistenceContext
来完成工作。
EntityManagerFactory
打算在webapp启动时只创建一次,在整个webapp的生命周期内重用,并在webapp关闭时关闭。它不应该在某个中途关闭,或者被序列化并重新用于下一个重启周期。
由于您显然是针对Glassfish,我强烈建议您不要自行管理,而是让Glassfish完成这项工作。您最终会得到更简单的EJB代码,而无需手动管理事务。
答案 2 :(得分:3)
我遇到了这个问题并找到了解决方案。
问题是eclipse(使用glassfish插件)只启动/停止域而不是数据库。
步骤:
详细说明:
我退出了eclipse - 这停止了glassfish服务器。然后关闭机器 - 停止数据库。重新启动时,打开eclipse,启动服务器并尝试部署相同的应用程序。失败,错误:
Deployment Error for module xxx
Error occurred during deployment: Exception while preparing the app :
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461):
org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Error in allocating a connection.
Cause: Connection could not be allocated because: java.net.ConnectException :
Error connecting to server localhost on port 1527 with message Connection refused
数据库未启动的原因。所以从命令行启动数据库。得到错误
java.lang.IllegalStateException: Attempting to execute an operation on a closed EntityManagerFactory
然后按照上面的步骤进行操作。
修改强> 以上步骤有时会解决问题,但在GF 3.0 / 3.1中它似乎也是一个众所周知的问题:http://java.net/jira/browse/GLASSFISH-17295
另一种选择是从管理控制台重新部署应用程序,如下所述:http://richardchesterwood.blogspot.in/2011/09/javaee-course-ships-with-copy-of-javaee.html