ConstructorResolver always uses arguments when completely provided
Issue: SPR-13808
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -683,7 +683,7 @@ class ConstructorResolver {
|
||||
// If we couldn't find a direct match and are not supposed to autowire,
|
||||
// let's try the next generic, untyped argument value as fallback:
|
||||
// it could match after type conversion (for example, String -> int).
|
||||
if (valueHolder == null && !autowiring) {
|
||||
if (valueHolder == null && (!autowiring || paramTypes.length == resolvedValues.getArgumentCount())) {
|
||||
valueHolder = resolvedValues.getGenericArgumentValue(null, null, usedValueHolders);
|
||||
}
|
||||
if (valueHolder != null) {
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.lang.annotation.Target;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
@@ -1827,6 +1828,18 @@ public class AutowiredAnnotationBeanPostProcessorTests {
|
||||
assertNotNull(bf.getBean(FooBar.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleConstructorWithProvidedArgument() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
|
||||
bpp.setBeanFactory(bf);
|
||||
bf.addBeanPostProcessor(bpp);
|
||||
RootBeanDefinition bd = new RootBeanDefinition(ProvidedArgumentBean.class);
|
||||
bd.getConstructorArgumentValues().addGenericArgumentValue(Collections.singletonList("value"));
|
||||
bf.registerBeanDefinition("beanWithArgs", bd);
|
||||
assertNotNull(bf.getBean(ProvidedArgumentBean.class));
|
||||
}
|
||||
|
||||
|
||||
public static class ResourceInjectionBean {
|
||||
|
||||
@@ -2920,4 +2933,11 @@ public class AutowiredAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class ProvidedArgumentBean {
|
||||
|
||||
public ProvidedArgumentBean(String[] args) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user