Home > database >  Spring Boot Repository Test with @DataJpaTest fails after update
Spring Boot Repository Test with @DataJpaTest fails after update

Time:04-14

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?

CodePudding user response:

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

@SpringBootTest 
@Transactional
  • Related