Skip to content

@ComponentScan on a test class is processed when creating a test context but is not included in the context's cache key #31577

@springframeworkguru

Description

@springframeworkguru

I have the following test, which works okay under Maven & Spring Boot 2.x.

AuthorDao bean fails to load when running under Maven and Spring Boot M3.

Works as expected when executing test under IntelliJ w/ Spring Boot M3.

This only is failing when running in a Maven context.

@ActiveProfiles("local")
@DataJpaTest
@ComponentScan(basePackages = {"guru.springframework.jdbc.dao"})
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
public class AuthorDaoIntegrationTest {

    @Autowired
    AuthorDao authorDao;

    @Test
    void testGetAuthor() {

        Author author = authorDao.getById(1L);

        assertThat(author).isNotNull();

    }
}

Error:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'guru.springframework.jdbc.dao.AuthorDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1779) ~[spring-beans-6.0.0-M4.jar:6.0.0-M4]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1338) ~[spring-beans-6.0.0-M4.jar:6.0.0-M4]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1292) ~[spring-beans-6.0.0-M4.jar:6.0.0-M4]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:717) ~[spring-beans-6.0.0-M4.jar:6.0.0-M4]
	... 72 common frames omitted

Gist of full build console output.

See complete project here. Note: Use branch "author-add-dao". (project is setup to run against local MySQL db using profile 'local' - sql init scripts under /src/scripts)

  • Oracle OpenJDK 17.0.2
  • Spring Boot 3.0.0-M3
  • Maven 3.8.1
  • Maven Surefire 2.22.2 (also tested with 3.0.0-M7, no change)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions