Skip to content

Commit d2108d2

Browse files
committed
Test for @resource @lazy fallback type match
See gh-31447
1 parent f9be717 commit d2108d2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,25 @@ public void testLazyResolutionWithCglibProxy() {
543543
assertThat(tb.getName()).isEqualTo("notLazyAnymore");
544544
}
545545

546+
@Test
547+
public void testLazyResolutionWithFallbackTypeMatch() {
548+
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
549+
bf.setAutowireCandidateResolver(new ContextAnnotationAutowireCandidateResolver());
550+
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
551+
bpp.setBeanFactory(bf);
552+
bf.addBeanPostProcessor(bpp);
553+
554+
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(LazyResourceCglibInjectionBean.class));
555+
bf.registerBeanDefinition("tb", new RootBeanDefinition(TestBean.class));
556+
557+
LazyResourceCglibInjectionBean bean = (LazyResourceCglibInjectionBean) bf.getBean("annotatedBean");
558+
assertThat(bf.containsSingleton("tb")).isFalse();
559+
bean.testBean.setName("notLazyAnymore");
560+
assertThat(bf.containsSingleton("tb")).isTrue();
561+
TestBean tb = (TestBean) bf.getBean("tb");
562+
assertThat(tb.getName()).isEqualTo("notLazyAnymore");
563+
}
564+
546565

547566
public static class AnnotatedInitDestroyBean {
548567

0 commit comments

Comments
 (0)