简体   繁体   中英

Spring Boot Repository Test with @DataJpaTest fails after update

I recently updated Spring Boot from 2.3 to 2.4. Since that all Repository tests failing with the error message:

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)}

My test looks like this:

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

   @Autowired
   Repository repositoryUnderTest;
}

This is the repository class:

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

As I said that just happened after the update. Before updating Spring Boot at version 2.3.12 everything was working fine. I already searched through the release notes but could not find anything which could cause this issue. Can anyone help?

The only way to get all the tests running again, was replacing @DataJpaTest with

@SpringBootTest 
@Transactional

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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