I'm using Spring Data JPA domain event as described in https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#core.domain-events. The event listener is marked with @Service
. It is working perfectly when I run it, but I can't make it works when testing it using @DataJpaTest
. If I replaced this with @SpringBootTest
, the test run perfectly.
I know that @DataJpaTest
will not load @Service
. But even if I add @Import(MyService.class)
, this will still not work. My question how do I test domain event with @DataJpaTest
without loading the full context as in @SpringBootTest
?