DAO层测试:java.lang.IllegalStateException:配置错误:为测试类找到@BootstrapWith的多个声明

时间:2019-12-21 15:14:05

标签: java spring-boot testing spring-data-jpa dao

我尝试使用Spring Boot对我的DAO层进行测试。但是我收到   java.lang.IllegalStateException: Configuration error: found multiple declarations of @BootstrapWith for test class [com.example.demo.FoodDaoIntegrationTest]

我已经读过几个关于此错误的答案,但仍然没有帮助。我猜注释仍然存在某种问题。 我的测试是:

package com.example.demo;
@RunWith(SpringRunner.class) @DataJpaTest
@SpringBootTest(classes = com.project.application.DemoApplication.class) 
@ContextConfiguration(classes = com.project.application.DemoApplication.class) 
public class FoodDaoIntegrationTest  {

@Autowired
private TestEntityManager entityManager;

@Autowired
private FoodDao mealDao;

@Test
public void TestSomething() {

1 个答案:

答案 0 :(得分:0)

注释中出现混乱。您不能混合使用SpringBootTest和DataJpaTest

尝试一下:

@RunWith(SpringRunner.class) 
@DataJpaTest
public class FoodDaoIntegrationTest  {