- 
                Notifications
    You must be signed in to change notification settings 
- Fork 38.8k
Description
Oliver Drotbohm opened SPR-10517 and commented
Assume the following FactoryBean implementation:
class FactoryBeanImpl implements FactoryBean, MyInterface { … }Beyond that, assume a BeanPostProcessor implementation that predicts the bean type of that FactoryBean to an arbitrary different type X. Now assume the following lookup code:
String[] names = beanFactory.getBeanNamesOfType(MyInterface.class);This call returns an empty array if the bean instance for FactoryBeanImpl has not been created, but returns the name of the bean (as expected) once the instance has been created.
The reason for that behavior seems to start in DefaultListableBeanFactory.doGetBeanNamesForType(…), at the line where we try to find the match for the factory bean name. This code calls {{isTypeMatch(…). The first step it does is trying to lookup an already existing instance. In our second case (bean has already been created before) we run in this if clause and finally end up in the ClassUtils.isAssignableValue(typeToMatch, beanInstance) call, which results int true being returned.
If no instance has been created we run down until the call to predictBeanType(…). This call will set beanClass to the predicted type so that the type match is done against the predicted bean type although we're testing the factory dereference explicitly. IMO the code has to be changed to:
Class<?> beanClass = BeanFactoryUtils.isFactoryDereference(name) ? resolveBeanClass(mbd, beanName, FactoryBean.class) : predictBeanType(beanName, mbd, FactoryBean.class, typeToMatch);Affects: 3.1.4, 3.2.2
Issue Links:
- DATAJPA-323 org.springframework.data.repository.support.Repositories doesn't find RepositoryFactoryInformation beans when using @EnableJpaRepositories("is depended on by")
- BeanFactory does not return FactoryBeans by type when using type prediction and bean not yet created [SPR-9177] #13815 BeanFactory does not return FactoryBeans by type when using type prediction and bean not yet created
- BeanFactory does not return FactoryBeans in case the are looked up by type and type prediction is used [SPR-8954] #13594 BeanFactory does not return FactoryBeans in case the are looked up by type and type prediction is used
Referenced from: commits bc3e585, ef363b0
0 votes, 5 watchers