diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java index e5acd029ea47..d5d9b9f871df 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -202,7 +202,6 @@ public BeanWrapper autowireConstructor(String beanName, RootBeanDefinition mbd, LinkedList causes = null; for (Constructor candidate : candidates) { - int parameterCount = candidate.getParameterCount(); if (constructorToUse != null && argsToUse != null && argsToUse.length > parameterCount) { @@ -515,8 +514,8 @@ public BeanWrapper instantiateUsingFactoryMethod( LinkedList causes = null; for (Method candidate : candidates) { - int parameterCount = candidate.getParameterCount(); + if (parameterCount >= minNrOfArgs) { ArgumentsHolder argsHolder; @@ -679,7 +678,7 @@ private int resolveConstructorArguments(String beanName, RootBeanDefinition mbd, throw new BeanCreationException(mbd.getResourceDescription(), beanName, "Invalid constructor argument index: " + index); } - if (index > minNrOfArgs) { + if (index + 1 > minNrOfArgs) { minNrOfArgs = index + 1; } ConstructorArgumentValues.ValueHolder valueHolder = entry.getValue();