Fix support for target arrays

This commits makes sure that a bean that produces an array can be
processed ahead of time. If the request target type is an array, its
component type is used.

Closes gh-31426
This commit is contained in:
Stéphane Nicoll
2023-10-13 15:33:26 +02:00
parent 85388aa642
commit 607c84f960
3 changed files with 48 additions and 1 deletions

View File

@@ -36,6 +36,7 @@ import org.springframework.beans.testfixture.beans.factory.aot.MockBeanRegistrat
import org.springframework.beans.testfixture.beans.factory.aot.MockBeanRegistrationsCode;
import org.springframework.beans.testfixture.beans.factory.aot.NumberFactoryBean;
import org.springframework.beans.testfixture.beans.factory.aot.SimpleBean;
import org.springframework.beans.testfixture.beans.factory.aot.SimpleBeanArrayFactoryBean;
import org.springframework.beans.testfixture.beans.factory.aot.SimpleBeanConfiguration;
import org.springframework.beans.testfixture.beans.factory.aot.SimpleBeanFactoryBean;
import org.springframework.core.ResolvableType;
@@ -76,6 +77,13 @@ class DefaultBeanRegistrationCodeFragmentsTests {
assertTarget(createInstance(registeredBean).getTarget(registeredBean), SimpleBean.class);
}
@Test
void getTargetOnConstructorToPublicFactoryBeanProducingArray() {
RegisteredBean registeredBean = registerTestBean(SimpleBean[].class,
SimpleBeanArrayFactoryBean.class.getDeclaredConstructors()[0]);
assertTarget(createInstance(registeredBean).getTarget(registeredBean), SimpleBean.class);
}
@Test
void getTargetOnConstructorToPublicGenericFactoryBeanExtractTargetFromFactoryBeanType() {
ResolvableType beanType = ResolvableType.forClassWithGenerics(