|
19 | 19 | import org.junit.Before;
|
20 | 20 | import org.junit.Test;
|
21 | 21 |
|
| 22 | +import org.springframework.aop.scope.ScopedObject; |
22 | 23 | import org.springframework.aop.scope.ScopedProxyUtils;
|
23 | 24 | import org.springframework.beans.factory.FactoryBean;
|
24 | 25 | import org.springframework.beans.factory.annotation.Autowired;
|
|
30 | 31 | import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
31 | 32 | import org.springframework.beans.factory.support.RootBeanDefinition;
|
32 | 33 | import org.springframework.core.io.DescriptiveResource;
|
| 34 | +import org.springframework.tests.sample.beans.ITestBean; |
33 | 35 | import org.springframework.tests.sample.beans.TestBean;
|
34 | 36 |
|
35 | 37 | import static org.junit.Assert.*;
|
@@ -139,6 +141,21 @@ public void testPostProcessorDoesNotOverrideRegularBeanDefinitionsEvenWithScoped
|
139 | 141 | beanFactory.getBean("bar", TestBean.class);
|
140 | 142 | }
|
141 | 143 |
|
| 144 | + @Test |
| 145 | + public void testScopedProxyTargetMarkedAsNonAutowireCandidate() { |
| 146 | + AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); |
| 147 | + bpp.setBeanFactory(beanFactory); |
| 148 | + beanFactory.addBeanPostProcessor(bpp); |
| 149 | + beanFactory.registerBeanDefinition("config", new RootBeanDefinition(ScopedProxyConfigurationClass.class)); |
| 150 | + beanFactory.registerBeanDefinition("consumer", new RootBeanDefinition(ScopedProxyConsumer.class)); |
| 151 | + ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor(); |
| 152 | + pp.postProcessBeanFactory(beanFactory); |
| 153 | + ITestBean injected = beanFactory.getBean("consumer", ScopedProxyConsumer.class).testBean; |
| 154 | + assertTrue(injected instanceof ScopedObject); |
| 155 | + assertSame(beanFactory.getBean("scopedClass"), injected); |
| 156 | + assertSame(beanFactory.getBean(ITestBean.class), injected); |
| 157 | + } |
| 158 | + |
142 | 159 | @Test
|
143 | 160 | public void testProcessingAllowedOnlyOncePerProcessorRegistryPair() {
|
144 | 161 | DefaultListableBeanFactory bf1 = new DefaultListableBeanFactory();
|
@@ -330,6 +347,23 @@ static class LoadedConfig {
|
330 | 347 | }
|
331 | 348 |
|
332 | 349 |
|
| 350 | + public static class ScopedProxyConsumer { |
| 351 | + |
| 352 | + @Autowired |
| 353 | + public ITestBean testBean; |
| 354 | + } |
| 355 | + |
| 356 | + |
| 357 | + @Configuration |
| 358 | + public static class ScopedProxyConfigurationClass { |
| 359 | + |
| 360 | + @Bean @Lazy @Scope(proxyMode=ScopedProxyMode.INTERFACES) |
| 361 | + public ITestBean scopedClass() { |
| 362 | + return new TestBean(); |
| 363 | + } |
| 364 | + } |
| 365 | + |
| 366 | + |
333 | 367 | public static class Repository<T> {
|
334 | 368 | }
|
335 | 369 |
|
|
0 commit comments