Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Named constructor args cannot be overridden by child bean definitions [SPR-6463] #11129

Closed
spring-projects-issues opened this issue Nov 27, 2009 · 2 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Nov 27, 2009

Jeffrey Sinclair opened SPR-6463 and commented

When I try to override a constructor arg by name in a child bean definition an exception arises which does not arise when I override the constructor arg by index.

I could be mistaken but I see this as a bug because if I can inherit by name and override by index, then I should also be able to override by name.

Specifically I've created an abstract bean definition as follows:

<bean id="abstractPerson" abstract="true">
  <constructor-arg value="Jeff Sinclair" name="name" />     
</bean>

I've then tried to create a concrete bean definition by overriding the named constructor arg:

  <bean id="concretePerson" class="test.spring.Person"
parent="abstractPerson">
    <constructor-arg value="Jeff S Sinclair" name="name" />     
  </bean>

This throws the following exception:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'concretePerson' defined in class path resource [test/spring/applicationContext.xml]: 
2 constructor arguments specified but no matching constructor found in bean 'concretePerson' 
(hint:specify index/type/name arguments for simple parameters to avoid type ambiguities)
        at
org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:171)
        ...
        at test.spring.Main.main(Main.java:9)   

Affects: 3.0 RC2

Issue Links:

Referenced from: commits 666700f

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Nov 29, 2009

Jeffrey Sinclair commented

Thought it would be worth referencing #10181 from this JIRA since part of the feature request in #10181 refers to constructor overriding. Of course #10181 is dealing with bean definition overriding rather than bean definition inheritance, however they are a little related.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Good point: Even if we're matching constructor argument names somewhat leniently (because they might not be available at runtime, hence the <constructor-arg> name values might be there for descriptive purposes only), it does make sense to allow for them to be overridden by name in child bean definitions.

Juergen

@spring-projects-issues spring-projects-issues added type: bug A general bug in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.0 RC3 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants