Getting a circular reference to entityManagerFactory when trying to use it in Spring Boot autoconfigured DataJpaTest

1.6k Views Asked by At

I'm migrating an application from Spring Boot 1.5.14.RELEASE to 2.0.4.RELEASE. I'm using Java 8 and Maven 3.5.4 if it matters. Please, see the complete project reproducing the issue here:

https://github.com/dmitrysenkovich/entity-manager-factory-test-example

I'm not sure if it works when running with spring-boot:run but that doesn't matter. So, please, run DaoTest and you will get:

BeanCurrentlyInCreationException: Error creating bean with name 'sessionFactory': Requested bean is currently in creation: Is there an unresolvable circular reference?

It is caused by entityManagerFactory being in creation at the moment it is needed in PersistenceTestConfig to create a sessingFactory bean. Seems like that it because Hibernate 5.2 SessionFactory extends EntityManagerFactory. But I'm stil not sure what the exact issue is.

Many thanks for any help!

0

There are 0 best solutions below