Skip to content

Improve Constructor Resolver Diagnostics [SPR-12543] #16975

Closed

Description

@spring-projects-issues

Gary Russell opened SPR-12543 and commented

throw new BeanCreationException(mbd.getResourceDescription(), beanName,
		"Could not resolve matching constructor " +
		"(hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)");

It would be helpful if the above exception (in ConstuctorResolver ) included the argument types in argToUse.


Affects: 4.1.3

Issue Links:

Referenced from: commits d55af2b

Activity

  1. spring-projects-issues commented on Dec 18, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Stéphane Nicoll commented

    out of curiosity how did you manage to reach that exception?

  2. spring-projects-issues commented on Dec 18, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Gary Russell commented

    Janne hit the problem in XD (https://gist.github.com/jvalkeal/cee35c9d0ddfe63fb25b). That turned out to be a class path problem, but I just thought it would be helpful to have included the types we were trying to wire in.

    It's not entirely clear to me why it manifested itself this way; after further debugging Janne Valkealahti found the bean (a factory bean) had a field defined with a class that was not on the class path. So I don't know why he didn't get a simple ClassNotFoundException when trying to construct the factory bean.

  3. spring-projects-issues commented on Dec 18, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Stéphane Nicoll commented

    Thanks Gary! - ping Juergen Hoeller

  4. spring-projects-issues commented on Dec 18, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Janne Valkealahti commented

    When I was tracking the problem without first knowing it to be a classpath issue, ConstuctorResolver around line 188 is eating the exception which is not propagated to end-user unless trace is enabled.

    catch (UnsatisfiedDependencyException ex) {
      if (this.beanFactory.logger.isTraceEnabled()) {
        this.beanFactory.logger.trace(
          "Ignoring constructor [" + candidate + "] of bean '" + beanName + "': " + ex);
    }
    

    Above catch had(if I remember location/line correctly):

    org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'ls.gateway': Unsatisfied dependency expressed through constructor argument with index 0 of type [java.lang.Class]: Could not convert constructor argument value of type [java.lang.String] to required type [java.lang.Class]: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Class'; nested exception is java.lang.IllegalArgumentException: Cannot find class [org.springframework.batch.integration.x.RemoteFilePartitioner$Gateway]
    

    Indeed it'd be nice to see this immediately without going so deep into core debugging.

  5. spring-projects-issues commented on Dec 23, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    The discrepancy is with whether there are additional constructors - with fewer parameters, e.g. a default constructor - around. In such cases, we would run into the general BeanCreationException code path, not the preferable "throw the last UnsatisfiedDependencyException" one.

    I've revised our algorithm to always handle recorded causes from previous resolution attempts right before we resort to BeanCreationException, consistently throwing the last UnsatisfiedDependencyException if possible.

    Juergen

  6. added
    type: enhancement
    in: core
    on Jan 11, 2019
  7. added this to the 4.1.4 milestone 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