Skip to content

Commit 66aeeed

Browse files
committed
Test injection point match for narrow target return type
Issue: SPR-14960 (cherry picked from commit 845dbf0)
1 parent af41dd1 commit 66aeeed

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorTests.java

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,12 @@ public void testNullArgumentThroughBeanMethodCall() {
609609
ctx.getBean("aFoo");
610610
}
611611

612+
@Test
613+
public void testInjectionPointMatchForNarrowTargetReturnType() {
614+
ApplicationContext ctx = new AnnotationConfigApplicationContext(FooBarConfiguration.class);
615+
assertSame(ctx.getBean(BarImpl.class), ctx.getBean(FooImpl.class).bar);
616+
}
617+
612618

613619
// -------------------------------------------------------------------------
614620

@@ -856,7 +862,7 @@ public static class SpecificRepositoryConfiguration {
856862

857863
@Bean
858864
public Repository<Object> genericRepo() {
859-
return new GenericRepository<Object>();
865+
return new GenericRepository<>();
860866
}
861867
}
862868

@@ -918,12 +924,12 @@ public static class WildcardWithExtendsConfiguration {
918924

919925
@Bean
920926
public Repository<? extends String> stringRepo() {
921-
return new Repository<String>();
927+
return new Repository<>();
922928
}
923929

924930
@Bean
925931
public Repository<? extends Number> numberRepo() {
926-
return new Repository<Number>();
932+
return new Repository<>();
927933
}
928934

929935
@Bean
@@ -942,7 +948,7 @@ public Repository<? extends Object> genericRepo() {
942948

943949
@Bean
944950
public Repository<? extends Number> numberRepo() {
945-
return new Repository<Number>();
951+
return new Repository<>();
946952
}
947953

948954
@Bean
@@ -1115,7 +1121,7 @@ public ServiceBean getServiceBean() {
11151121
@Configuration
11161122
public static class A {
11171123

1118-
@Autowired(required=true)
1124+
@Autowired(required = true)
11191125
Z z;
11201126

11211127
@Bean
@@ -1221,4 +1227,30 @@ static abstract class FooFactory {
12211227
abstract DependingFoo createFoo(BarArgument bar);
12221228
}
12231229

1230+
interface BarInterface {
1231+
}
1232+
1233+
static class BarImpl implements BarInterface {
1234+
}
1235+
1236+
static class FooImpl {
1237+
1238+
@Autowired
1239+
public BarImpl bar;
1240+
}
1241+
1242+
@Configuration
1243+
static class FooBarConfiguration {
1244+
1245+
@Bean @DependsOn("bar")
1246+
public FooImpl foo() {
1247+
return new FooImpl();
1248+
}
1249+
1250+
@Bean
1251+
public BarInterface bar() {
1252+
return new BarImpl();
1253+
}
1254+
}
1255+
12241256
}

0 commit comments

Comments
 (0)