-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
Ryan Gardner opened SPR-11019 and commented
I created some bean definitions in my BeanRegistry and was using indexed constructor arguments.
When using @Resource
, the beans were resolved properly by type.
When using @Autowired
, they were not found.
We traced it down to:
line 635 of the AbstractAutowireCapableBeanFactory in the getTypeForFactoryMethod method
List<ValueHolder> argumentValues = mbd.getConstructorArgumentValues().getGenericArgumentValues();
This code only looks for methods based on argument values set as GenericArgumentValues - any set via indexedArgumentValues are not found.
switching our code to create bean definitions using GenericArgumentValues instead of IndexedArgumentValues fixed the issue for us, but this seems like an oversight.
Changing it slightly to something like this should at least address this one case:
List<ValueHolder> argumentValues = mbd.getConstructorArgumentValues().getGenericArgumentValues();
if (argumentValues.size() == 0) {
argumentValues = mbd.getConstructorArgumentValues().getIndexedArgumentValues();
}
(feel free to use the above code - I've signed the spring contributor agreement... if you want I can do this on a branch and submit a pull request for it)
Affects: 3.2.4