【发布时间】:2018-01-25 13:34:35
【问题描述】:
我正在使用 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 那样加载完整的上下文?
【问题讨论】:
标签: spring-boot spring-data-jpa spring-boot-test