我正在使用https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#core.domain-events中所述的 Spring Data JPA 域事件。事件侦听器标有@Service。当我运行它时它运行良好,但是在使用@DataJpaTest. 如果我将其替换为@SpringBootTest,则测试运行完美。
我知道@DataJpaTest不会加载@Service。但即使我添加@Import(MyService.class),这仍然行不通。我的问题如何在@DataJpaTest不加载完整上下文的情况下测试域事件@SpringBootTest?