繁体   English   中英

Spring 更新后使用@DataJpaTest 的引导存储库测试失败

[英]Spring Boot Repository Test with @DataJpaTest fails after update

我最近将 Spring Boot 从 2.3 更新到 2.4。 因为所有存储库测试都失败并显示错误消息:

org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为“...RepositoryTest”的 bean 时出错:通过字段“repositoryUnderTest”表示的不满意依赖关系; 嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException:没有可用类型为“...Repository”的合格 bean:预计至少有 1 个 bean 有资格作为自动装配候选者。 依赖注解:{@org.springframework.beans.factory.annotation.Autowired(required=true)}

我的测试看起来像这样:

@RunWith(SpringRunner.class)
@DataJpaTest
@Profile("test")
public class RepositoryTest {

   @Autowired
   Repository repositoryUnderTest;
}

这是存储库 class:

@Repository
public interface Repository extends JpaRepository<Entity, Long> {
   ...
}

正如我所说,那只是在更新后发生的。 在更新 Spring Boot 2.3.12 之前一切正常。 我已经搜索了发行说明,但找不到任何可能导致此问题的内容。 谁能帮忙?

使所有测试再次运行的唯一方法是将@DataJpaTest替换为

@SpringBootTest 
@Transactional

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM