-
Notifications
You must be signed in to change notification settings - Fork 38.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BeanNameAutoProxyCreator proxies the wrong beans when custom TargetSourceCreator specified #24915
Comments
Thanks for pointing this out. In your particular example, the However, since That's the part that is counter-intuitive, and we'll address that in 5.3 by ensuring that a custom |
Hi @sbrannen. The use of |
Indeed. I was merely pointing out that a
I think one can certainly view that as a bug in the sense that it was probably unintentional. However, this behavior has been in place for a long time, and people may have come to rely on this "accidental feature". That's why we have currently slated the fix for 5.3 in order to avoid breaking code relying on this in previous releases. Speaking of which, are you hoping to see this fix applied to 5.2.7 or any earlier branches? |
The proposed fix can be viewed here: sbrannen@5eda469 |
That was my hope, but I appreciate that this is old code, old enough as you say that people my be relying on the "broken" behaviour, which makes it hard to back-port. |
Thanks for the feedback, @kennymacleod. This has been addressed in 3c3e8e6 for Spring Framework 5.3. |
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 spring-projectsgh-24915
Spring 5.1.8 (but also probably earlier versions)
Short version: if you use
BeanNameAutoProxyCreator
with a customTargetSourceCreator
, you'll get proxies created for all of your beans, not just the ones listed in thebeanNames
property.Longer version:
BeanNameAutoProxyCreator
allows you to specify thebeanNames
for which you want proxies to be created. It also allows you to specify one of moreTargetSourceCreators
. However, theTargetSourceCreator
will be asked to createTargetSource
for every bean in the context, not just the beans listed inbeanNames
.To reproduce the problem, I created a simple context with 2 beans and a unit test (see below). The context contains a
BeanNameAutoProxyCreator
and specifies that onlybeanA
should be proxied. BothbeanA
andbeanB
are declared aslazy-init
, and I've specified aLazyInitTargetSourceCreator
to be used (the lazy-init-ness isn't particularly important, it's just an off-the-shelf implementation ofTargetSourceCreator
that demonstrates the problem).The unit test asserts that
BeanA
is a proxy andbeanB
is not, but then fails because both beans have been proxied.This is at the very least unexpected and confusing (and should be documented), and is probably a bug. The
TargetSourceCreator
is being asked for aTargetSource
for every bean in the context, without checking for which beans should be candidates for being proxied.The text was updated successfully, but these errors were encountered: