首页 > 解决方案 > DAO 层测试:java.lang.IllegalStateException:配置错误:为测试类找到多个@BootstrapWith 声明

问题描述

我尝试使用 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() {

标签: javaspring-boottestingspring-data-jpadao

解决方案


你的注释很混乱。你不能混合 SpringBootTest 和 DataJpaTest

尝试这个:

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

推荐阅读