Skip to content

Commit 845dbf0

Browse files
committed
Test injection point match for narrow target return type
Issue: SPR-14960
1 parent 1ae17c2 commit 845dbf0

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

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

+33-1
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

@@ -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)