ConstructorResolver exposes parameter signature from user-declared class (in case of a CGLIB-generated subclass)

Issue: SPR-14015
This commit is contained in:
Juergen Hoeller
2016-03-11 12:52:40 +01:00
parent b6f69492a3
commit b944283354
2 changed files with 44 additions and 5 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
@@ -26,6 +26,7 @@ import javax.inject.Provider;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
@@ -103,6 +104,18 @@ public class AutowiredConfigurationTests {
assertSame(ctx.getBean(AutowiredConstructorConfig.class).colour, ctx.getBean(Colour.class));
}
@Test
public void testObjectFactoryConstructorWithTypeVariable() {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(factory).loadBeanDefinitions(
new ClassPathResource("annotation-config.xml", ObjectFactoryConstructorConfig.class));
GenericApplicationContext ctx = new GenericApplicationContext(factory);
ctx.registerBeanDefinition("config1", new RootBeanDefinition(ObjectFactoryConstructorConfig.class));
ctx.registerBeanDefinition("config2", new RootBeanDefinition(ColorConfig.class));
ctx.refresh();
assertSame(ctx.getBean(ObjectFactoryConstructorConfig.class).colour, ctx.getBean(Colour.class));
}
@Test
public void testAutowiredAnnotatedConstructorSupported() {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
@@ -257,6 +270,18 @@ public class AutowiredConfigurationTests {
}
@Configuration
static class ObjectFactoryConstructorConfig {
Colour colour;
// @Autowired
ObjectFactoryConstructorConfig(ObjectFactory<Colour> colourFactory) {
this.colour = colourFactory.getObject();
}
}
@Configuration
static class MultipleConstructorConfig {