当我在本地运行spring项目时,我没有任何异常。但是在服务器上部署时,我得到:
org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is java.lang.IllegalStateException: EntityManagerFactory is closed
at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:450)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:378)
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:474)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:289)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
at com.scoring.main.services.implementations.BlockNumberServiceImpl$$EnhancerBySpringCGLIB$$dd6e9601.getBlockNumberPair(<generated>)
at com.scoring.main.services.implementations.ListenerServiceImpl.getAllActualTransactions(ListenerServiceImpl.java:48)
at com.scoring.main.listeners.TransactionEventListener.lambda$new$1(TransactionEventListener.java:60)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalStateException: EntityManagerFactory is closed
at org.hibernate.internal.SessionFactoryImpl.validateNotClosed(SessionFactoryImpl.java:498)
at org.hibernate.internal.SessionFactoryImpl.buildEntityManager(SessionFactoryImpl.java:573)
at org.hibernate.internal.SessionFactoryImpl.createEntityManager(SessionFactoryImpl.java:569)
at org.hibernate.internal.SessionFactoryImpl.createEntityManager(SessionFactoryImpl.java:155)
at org.springframework.orm.jpa.JpaTransactionManager.createEntityManagerForTransaction(JpaTransactionManager.java:468)
at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:389)
... 16 more
我正在使用Spring Data Jpa,并且存储库类扩展了JpaRepository。 在日志中,我了解了getBlockNumberPair方法中的BlockNumberService问题。这是我的方法的外观:
@Transactional(readOnly = true)
@Override
public BlockNumber getBlockNumberPair() {
return blockNumberRepository.findById(1L).get();
}
问题出在哪里,为什么在本地可行?
答案 0 :(得分:0)
通过重新启动服务器来解决。
更新:
这是詹金斯配置中的错误。我只是将我的项目推到Github中,Jenkins部署了项目。事实证明,在由詹金斯(Jenkins)重新部署之后,我启动Tomcat服务器的数量与进入Github的数量一样多,而在日志中,我得到了该例外。但是有趣的是,它如何在同一个端口中启动许多进程?在这种情况下,不应启动服务器。