【发布时间】:2018-04-17 20:47:05
【问题描述】:
我正在尝试在 Spring Boot 项目中加载应用程序属性以进行测试。我也在使用@DataJpaTest 注释。许多人建议将@TestPropertySource 注释与@datajpaTest 结合使用,但它不加载属性。如果我使用@SpringBooTest,它正在加载属性。
@RunWith(SpringRunner.class)
@DataJpaTest
@TestPropertySource(locations="classpath:application.properties")
public class EntityRepositoryTests {
}
我的应用程序属性文件位于 main/resource/ 文件夹中。
如果我使用@SpringBootTest(properties = { "classpath:application.properties" },它就可以工作,但我有
@Autowired
private TestEntityManager entityManager;
无法使用 SpringBootTest 进行自动配置。我也尝试过@ContextConfiguration(initializers=ConfigFileApplicationContextInitializer.class),但没有运气。
【问题讨论】:
标签: spring unit-testing spring-data-jpa