spring-data-jpa 无法打开事务的JPA EntityManager;嵌套的异常是java.lang.IllegalStateException:实体管理器工厂已关闭

6ie5vjzr  于 2022-11-10  发布在  Spring
关注(0)|答案(1)|浏览(414)

当我在本地运行我的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和repository类扩展JpaRepository。在日志中,我发现方法getBlockNumberPair中的BlockNumberService有问题。这是我的方法的外观:

@Transactional(readOnly = true)
@Override
public BlockNumber getBlockNumberPair() {
    return blockNumberRepository.findById(1L).get();
}

问题出在哪里?为什么它在当地有效?

i34xakig

i34xakig1#

通过重新启动服务器解决。

更新日期:

这是Jenkins中的配置错误。我只是把我的项目推到Github中,Jenkins部署了项目。在Jenkins重新部署之后,我已经启动了和我推到Github中一样多的tomcat服务器,并且在log中我得到了这个异常。但是有趣的是,它是如何在同一个端口启动很多进程的?在这种情况下,服务器不应该启动。

相关问题