Skip to content

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

Closed

Description

@spring-projects-issues

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:

Activity

  1. spring-projects-issues commented on Feb 26, 2016

    @spring-projects-issues
    CollaboratorAuthor

    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

  2. spring-projects-issues commented on Mar 18, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

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

    Juergen

  3. spring-projects-issues commented on May 23, 2016

    @spring-projects-issues
    CollaboratorAuthor

    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.

  4. spring-projects-issues commented on Jun 9, 2016

    @spring-projects-issues
    CollaboratorAuthor

    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?

  5. added
    type: enhancement
    in: core
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: coretype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions