Given a RootBeanDefinition for a FactoryBean that exposes a generic for the bean that it produces (typically Spring Data repositories infrastructure):

RootBeanDefinition beanDefinition = new RootBeanDefinition(JpaRepositoryFactoryBean.class);
beanDefinition.setTargetType(ResolvableType.forClassWithGenerics(JpaRepositoryFactoryBean.class,
        CityRepository.class, Object.class, Object.class));

A call to getBeanNamesForType with CityRepository.class does not return the bean definition. It looks like the target type is not taken into account to resolve the FactoryBean's generic type, if available.

Failing test case at: https://github.com/snicoll/spring-framework/commit/edb8a052c3be257f9fb5813aae9b7defbb9d5a35