Skip to content

BeanFactoryUtils.beanNamesForTypeIncludingAncestors(factory, RepositoryFactoryInformation.class, false, false) doesn't find beans that are found in 4.1 [SPR-12846] #17444

@spring-projects-issues

Description

@spring-projects-issues

Andy Wilkinson opened SPR-12846 and commented

A Spring Data JPA-based test is failing in Spring Boot when I upgrade to Spring Framework 4.2. The failure occurs because Spring Data's Repositories class fails to find the JpaRepositoryFactoryBean in the application context. It looks for it by calling BeanFactoryUtils.beanNamesForTypeIncludingAncestors(factory, RepositoryFactoryInformation.class, false, false)). RepositoryFactoryInformation is an interface that is implemented by JpaRepositoryFactoryInformation.

The problem looks like it may be due to the use of ResolvableType in 4.2. When run against Spring Framework 4.1.x, it boils down to AbstractBeanFactory.isTypeMatch calling org.springframework.data.repository.core.support.RepositoryFactoryInformation.class.isAssignableFrom(org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.class). When run against Spring Framework 4.2 it's the ResolvableType for RepositoryFactoryInformation that's used. In 4.1.x the isAssignableFrom call returns true, in 4.2 it returns false. This is summarised in the following test:

assertTrue(RepositoryFactoryInformation.class
        .isAssignableFrom(JpaRepositoryFactoryBean.class));
assertTrue(ResolvableType.forClass(RepositoryFactoryInformation.class)
        .isAssignableFrom(JpaRepositoryFactoryBean.class));

It fails on the second assertion.


Affects: 4.2 RC1

Referenced from: commits 09027f7

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions