Skip to content

Unique XML-specified constructor not accepted in case of unresolvable name [SPR-13987] #18559

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

Closed
spring-projects-issues opened this issue Feb 26, 2016 · 4 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Feb 26, 2016

Thibault Kruse opened SPR-13987 and commented

To reproduce:

<bean id="myExecutor" class="java.util.concurrent.ScheduledThreadPoolExecutor">
     <constructor-arg name="corePoolSize" index="0" type="int" value="1" />
     <!-- works: <constructor-arg index="0" type="int" value="1" /> -->
</bean>

fails with:

Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myExecutor' defined in class path resource [applicationContext-test.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [int]: Ambiguous constructor argument types - did you specify the correct bean references as constructor arguments?

Class ScheduledThreadPoolExecutor has only one 1-arg constructor:
public ScheduledThreadPoolExecutor(int corePoolSize)

If not a bug, I would suggest improving the error message and the documentation in spring-beans.xsd.

Also see one of the comments here from 2013:
http://stackoverflow.com/questions/17387544/unsatisfied-dependency-expressed-through-constructor-argument-with-index-0-of-ty


Affects: 4.2.4

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Looks like this is because the java.util.concurrent.ScheduledThreadPoolExecutor (like all of the JDK's rt.jar) is not compiled with -parameters, so we can't resolve the parameter name... However, unfortunately, we insist on resolving the name even in cases where the constructor specification is unique in any case! And indeed, the wording of the exception message should be improved, but for this particular case, the configuration should actually just get accepted and work fine at runtime.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

I've revised our ConstructorArgumentValues holder to leniently allow for matches if the required name is not resolvable.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Guram Savinov commented

  1. Why name is a problem for resolving if index specified?
  2. Why constructor resolver doesn't understand that if I specify only one argument I want constructor with one argument? For example this doesn't work:

<bean id="blockingQueue" class="java.util.concurrent.ArrayBlockingQueue" c:capacity="100" />
This class has three constructors with one, two and three arguments.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

As per these changes in 4.3 RC1, your scenarios should work fine. Have you tried RC1, or even better RC2 or the latest 4.3.0.BUILD-SNAPSHOT?

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: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants