Skip to content
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

Interception through CGLIB subclassing of target bean class (without a proxy) [SPR-16114] #20662

Open
spring-projects-issues opened this issue Oct 25, 2017 · 1 comment
Labels
in: core type: enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Oct 25, 2017

John Doe opened SPR-16114 and commented

When using cglib proxy, 'this' should be the proxy (like for the @Configuration classes), making internal calls eligible for interception. It is how cglib Enhancer works, @Configuration also works this way but not @Component beans (nor objects created from @Import or @Bean).

if there is a good reason for this different behaviors maybe it should be documented.


No further details from SPR-16114

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 25, 2017

Juergen Hoeller commented

This is simply due to the proxy nature of Spring AOP: Like with an interface-based proxy, a CGLIB proxy is a separate instance in front of the actual target object. This allows for a decoupled lifecycle, e.g. lazy initialization or prototype/request/session scoping for the target object, with a stable proxy instance as a front facade that can be shared and injected anywhere.

You got a point that, in principle, we could also provide an interception model based on runtime-generated CGLIB subclasses which replace the original bean class instead of serving as a proxy, just supporting interceptors and no individual target lifecycle. However, that would be yet another model with distinct characteristics, in addition to the target-class proxy model... and also in addition to AspectJ weaving (modifying the bytecode of the original bean class without proxying or subclassing and therefore providing the desired 'this' semantics in a different way) which we're supporting for several Spring features already.

@spring-projects-issues spring-projects-issues added type: enhancement in: core labels Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core type: enhancement
Projects
None yet
Development

No branches or pull requests

1 participant