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
ProxyFactoryBean getObject called before setInterceptorNames, silently creating an invalid proxy [SPR-7582] #12238
Comments
nigel magnay commented I have tried this with Spring 3, and it's a problem there too. In fact, there are also scenarios where ProxyFactoryBean is re-entered because of a loop (because of executing getBeanNamesForType(), not a real dependency loop), where you then end up with many multiples of the interceptors created. |
Alar Kvell commented I can confirm this with Spring 2.0.8 I used a workaround: in afterPropertiesSet method, set advisorChainInitialized to false. |
Bulk closing outdated, unresolved issues. Please, reopen if still relevant. |
This is still an issue |
@marijnm, would you be willing to provide a simple example project that demonstrates the issue -- for example, if the form of a GitHub repository or ZIP file that we can download and use to reproduce the issue? |
I'm facing the same problem. Detailed description: https://stackoverflow.com/questions/66133760/spring-proxyfactorybean-interceptor-advice-sometimes-not-called-missing The ProxyFactoryBean also tries multiple times to create the Proxy while it's not initialized:
After the first call of Maybe advisorChainInitialized should be set to false here before throwing the exception. Spring version: 5.1.15.RELEASE |
I'm seeing behaviour that looks very like this (i.e. I'm using Spring Framework 5.1.18. |
nigel magnay opened SPR-7582 and commented
We have an application that uses a fairly standard pattern to declare a proxy for a bean:
The instantiation order causes this bean to be being created in response to an unrelated autowiring request, e.g:
Which is internally executing
getBeanNamesForType()
.This causes a chain of objects to be created, and the
ProxyFactoryBean
forAService
to be called withgetObject()
.However, this
getObject()
call is in advance of Spring having set theinterceptorNames
. Thus the proxy is created, and theadvisorChainInitialized
variable set totrue
with no interceptor names.There's several things here
getObject
on an uninitialized factory; it ought to have set the properties first. I don't believe there are circular dependencies here (since it is initiated by a request to find all instances of an unrelated class). I can remove the problem (for one bean, but this applies to many) by creating a derived type ofProxyFactoryBean
that sets the target andinterceptorNames
on construction... but this seems to be a nasty workaround as I'd have to set it for many, many beans. If it believes there to be a circular dependency I'd expect an exception.setInterceptorNames
finds thatadvisorChainInitialized == true
, it ought to throw an exception, since it is clearly too late to influence the interception chain (so for example security interceptors mysteriously fail to work).Affects: 2.5.6
Attachments:
Referenced from: pull request #1477
2 votes, 3 watchers
The text was updated successfully, but these errors were encountered: