Support for creating AOP proxies at Runtime if necessary#12223
Conversation
sdelamo
left a comment
There was a problem hiding this comment.
@dstepanov Can you provide a PR description that describes why we need this PR?
| * @param <T> The proxied bean type | ||
| * @return The proxy instance | ||
| */ | ||
| <T> T createProxy(RuntimeProxyDefinition<T> proxyDefinition); |
There was a problem hiding this comment.
if I don't need proxying how would I return the original bean?
There was a problem hiding this comment.
Nothing is created at this moment, so you instantiate it yourself with the constructor values provided or if it's the target proxy you have to get it from the proxy definition
There was a problem hiding this comment.
To explain it a bit more, we have two ways of generating a proxy; with a proxy target or without.
With a proxy target we get the target bean instance from the bean context, and delegate the non-intercepted call to it. In a case of a no-proxy-target we simply extend the class and create an extra methods that do the super-call.
If you don't want to override the class at the runtime, you will need to add @Around(proxyTarget=true)
d247724 to
932f072
Compare
| * | ||
| * @return The runtime proxy creator bean class | ||
| */ | ||
| Class<? extends RuntimeProxyCreator> value(); |
There was a problem hiding this comment.
could we have something in this annotation that activates @Around(proxyTarget=true) behaviour
There was a problem hiding this comment.
I can add proxyTarget to it
|
|
||
| @Singleton | ||
| @NullMarked | ||
| public class JdkRuntimeProxy implements RuntimeProxyCreator { |
There was a problem hiding this comment.
would be good to add a test Groovy implementation that returns the original instance and uses runtime Groovy meta-programming to replace the method and proxy instead. This will further validate what we are trying to achieve. See https://groovy-lang.org/metaprogramming.html#metaprogramming_emc
|




When annotating with
@RuntimeProxy(MyCreator.class)we will not generate a proxy class that intercept the bean, instead we allow for the proxy to be created at the runtime.Use-cases:
In this case we will generate only the bean definition without a proxy implementation: