java - 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() {
解决方案
你的注释很混乱。你不能混合 SpringBootTest 和 DataJpaTest
尝试这个:
@RunWith(SpringRunner.class)
@DataJpaTest
public class FoodDaoIntegrationTest {
推荐阅读
- mongodb - 为什么它不能显示超过 2 个作者的书籍?
- java - 7.0.100+ 中 Tomcat 中的客户端证书身份验证问题
- c# - 更新行后有效刷新DataGridView
- javascript - 为什么我的第二个标签页没有显示在 ONSEN UI 中
- react-native - 使用 Detox 和 React Native 更改应用程序入口点
- docker - docker 运行中受 -it 参数影响的 docker 日志
- python-3.x - 使用python中的PIL合并文件夹中的多个图像时的颜色扩散
- postgresql - 如何列出两列连接的双重条目?
- android - 动态功能导航:找不到资源
- java - java,给定一个HashMap,如何根据频率(hm)将HM数组织成一个新数组?