1

I'm trying to test my controller, in my test class when I annotate it with @SpringBootTest(classes = BootloaderApplicationLauncher.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) my test pass but when I try to annotate it with @WebMvcTest(controllers = ReleveBancaireControllerImpl.class) my application throws this exception:

Parameter 0 of constructor in persistence.jpa.adapter.ReleveBancaireSpringJpaAdapter required a bean named 'entityManagerFactory' that could not be found.


Action:

Consider defining a bean named 'entityManagerFactory' in your configuration.

I using maven multi modules.
I added all my configuration when I start the application works fine.
I just want to test my controller with @WebMvcTest
Spring boot version: 2.3.1.RELEASE
hibernate-entitymanager version: 5.0.0.Final
Hibernate-core version: 5.6.5.Final

Full exception:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'releveBancaireRepository': Cannot create inner bean '(inner bean)#3c81cd82' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#3c81cd82': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#3c81cd82': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available
BAKHALED Ibrahim
  • 473
  • 1
  • 7
  • 19
  • https://stackoverflow.com/a/46461367/10042529 https://stackoverflow.com/a/47351315/10042529 These two answers might help you – xiaobo9 Apr 05 '22 at 09:54

0 Answers0