Spring 更新后使用@DataJpaTest 启动存储库测试失败

Spring Boot Repository Test with @DataJpaTest fails after update

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

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name '...RepositoryTest': Unsatisfied dependency expressed through field 'repositoryUnderTest'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type '...Repository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@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 版本 2.3.12 引导之前一切正常。我已经搜索了发行说明,但找不到任何可能导致此问题的内容。有人可以帮忙吗?

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

@SpringBootTest 
@Transactional