Only proxy supported beans in BeanNameAutoProxyCreator

Prior to this commit, if a BeanNameAutoProxyCreator was configured with
a custom TargetSourceCreator, the TargetSourceCreator was applied to
all beans in the ApplicationContext. Thus, the list of supported
beanNames was effectively ignored when applying any
TargetSourceCreator. Consequently, if a TargetSourceCreator returned a
non-null TargetSource for a given bean, the BeanNameAutoProxyCreator
proxied the bean even if the bean name had not been configured in the
beanNames list.

This commit addresses this issue by ensuring that a custom
TargetSourceCreator is only applied to beans whose names match the
configured beanNames list in a BeanNameAutoProxyCreator.

Closes gh-24915
This commit is contained in:
Sam Brannen
2020-05-11 19:48:43 +02:00
parent a07dc80d72
commit 3c3e8e6a8b
3 changed files with 80 additions and 13 deletions

View File

@@ -155,6 +155,16 @@ class BeanNameAutoProxyCreatorTests {
assertThat(((Advised)testBean).isFrozen()).isTrue();
}
@Test
void customTargetSourceCreatorsApplyOnlyToConfiguredBeanNames() {
ITestBean lazy1 = beanFactory.getBean("lazy1", ITestBean.class);
ITestBean alias1 = beanFactory.getBean("lazy1alias", ITestBean.class);
ITestBean lazy2 = beanFactory.getBean("lazy2", ITestBean.class);
assertThat(AopUtils.isAopProxy(lazy1)).isTrue();
assertThat(AopUtils.isAopProxy(alias1)).isTrue();
assertThat(AopUtils.isAopProxy(lazy2)).isFalse();
}
private void jdkAssertions(ITestBean tb, int nopInterceptorCount) {
NopInterceptor nop = (NopInterceptor) beanFactory.getBean("nopInterceptor");