无法在测试中修复“ EntityManagerFactory已关闭”

问题描述

我正在开发一个用Scala 2.11编写的项目,我们还使用Spring Boot 2.0和maven进行构建(这是一个多模块项目)。这也不是Web应用程序。

为了解决以下问题,我已经坚持了数周,这只有在使用maven对特定模块运行完整的测试集时才会发生:(mvn clean install -pl:workflow)

在运行单个测试甚至在隔离的程序包中进行多个测试时,都不会发生这种情况。

 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:448)
  at org.springframework.transaction.support.AbstractPlatformTransactionManager.startTransaction(AbstractPlatformTransactionManager.java:400)
  at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)
  at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:574)
  at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:361)
  at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118)
  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
  at org.springframework.aop.framework.cglibAopProxy$cglibMethodInvocation.proceed(cglibAopProxy.java:749)
  at org.springframework.aop.framework.cglibAopProxy$DynamicAdvisedInterceptor.intercept(cglibAopProxy.java:691)
  at edu.ucdavis.fiehnlab.ms.carrot.core.db.jpa.JPALibraryAccess$$EnhancerBySpringcglib$$773e5887.load(<generated>)
  ...
  Cause: java.lang.IllegalStateException: EntityManagerFactory is closed
  at org.hibernate.internal.SessionFactoryImpl.validateNotClosed(SessionFactoryImpl.java:509)
  at org.hibernate.internal.SessionFactoryImpl.createEntityManager(SessionFactoryImpl.java:588)
  at org.hibernate.internal.SessionFactoryImpl.createEntityManager(SessionFactoryImpl.java:156)
  at org.springframework.orm.jpa.JpaTransactionManager.createEntityManagerForTransaction(JpaTransactionManager.java:466)
  at org.springframework.orm.jpa.JpaTransactionManager.dobegin(JpaTransactionManager.java:391)
  at org.springframework.transaction.support.AbstractPlatformTransactionManager.startTransaction(AbstractPlatformTransactionManager.java:400)
  at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)
  at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:574)
  at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:361)
  at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118)

任何和所有与EntityManager相关的bean都由Spring处理。

我们已经为使用数据库客户端的所有测试添加了@Transactional批注;还添加了@DirtiesContext,没有任何更改。

我将非常感谢您提供有关调试/修复此问题的帮助或指示。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)