Skip to content

Bean definitions using indexed constructor arguments are not usable for @Autowired resolution [SPR-11019] #15647

@spring-projects-issues

Description

@spring-projects-issues

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

Referenced from: commits 42568af, 109faac

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions