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:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user