For JDK dynamic proxies created by Spring's AOP support, SpringProxy
, Advised
, and DecoratingProxy
will often be included in the interfaces that the proxy implements.
Here's an example taken from Spring Integration.
proxyHints
.registerJdkProxy(RequestReplyExchanger.class, SpringProxy.class, Advised.class, DecoratingProxy.class)
.registerJdkProxy(AbstractReplyProducingMessageHandler.RequestHandler.class, SpringProxy.class, Advised.class, DecoratingProxy.class)
.registerJdkProxy(IntegrationFlow.class, SmartLifecycle.class, SpringProxy.class, Advised.class, DecoratingProxy.class);
We should investigate options for simplifying the proxy hint registration for Spring AOP proxies so that users are not required to specify SpringProxy
, Advised
, and DecoratingProxy
.
One option would be to introduce a new registerSpringJdkProxy(...)
method (or similar) in ProxyHints
that automatically registers the required Spring AOP interfaces. Though, it is not always the case that all 3 of those interfaces are implemented by the proxy. So we could document that this particular registerSpringJdkProxy(...)
variant always registers those 3 particular interfaces to cover common use cases and allow users to continue to use registerJdkProxy(...)
when the additional Spring AOP interfaces differ from that common set of 3.
Comment From: snicoll
We can't really do that, can we? Spring AOP is higher in the dependency tree. Perhaps something along the lines of RuntimeHintsUtils, but for SpringAopProxy?
I am afk but perhaps AopUtils could be used?
Comment From: sbrannen
Spring AOP is higher in the dependency tree.
That's a good point. We definitely cannot refer to the Class
references, and it does unfortunately seem a bit out of place to be talking about Spring AOP in Spring Core.
We can't really do that, can we?
Well, by using the class names we can implement it like this:
public ProxyHints registerSpringAopJdkProxy(Class<?>... proxiedInterfaces) {
return registerJdkProxy(jdkProxyHint -> {
jdkProxyHint.proxiedInterfaces(proxiedInterfaces);
jdkProxyHint.proxiedInterfaces(
TypeReference.of("org.springframework.aop.SpringProxy"),
TypeReference.of("org.springframework.aop.framework.Advised"),
TypeReference.of("org.springframework.core.DecoratingProxy"));
});
}
Perhaps something along the lines of RuntimeHintsUtils, but for SpringAopProxy?
Sure. If we don't want to use the class name based approach I pasted above, we could introduce something along the lines of RuntimeHintsUtils
for Spring AOP proxies in spring-aop
.
I am afk but perhaps AopUtils could be used?
Not that I'm aware of.
Comment From: snicoll
Well, by using the class names we can implement it like this:
That sounds like hiding a conceptual cycle to me.
Sure. If we don't want to use the class name based approach I pasted above,
Are we doing this elsewhere, except in Javadoc links?
Not that I'm aware of.
How do you mean? I believe AopUtils#registerAopProxyHints(Class<?>... proxiedInterfaces)
could be a possibility.
Comment From: sbrannen
Team Decision:
- Introduce static utility methods in
AopProxyUtils
that combine user provided interfaces withSpringProxy
,Advised
, andDecoratingProxy
. - This method could be named something along the lines of
completeProxiedInterfaces()
to align with the existing methods in that class. - We will need to two variants, one accepting
Class<?>...
and one acceptingTypeReference...
. - The returned arrays should be able to be supplied as input to both variants of
proxyHints.registerJdkProxy()
. - Cross reference these new methods from the Javadoc in the existing
registerJdkProxy()
methods inspring-core
to make the AOP specific support discoverable via the core user API.
Comment From: snicoll
Cross reference these new methods from the Javadoc in the existing registerJdkProxy() methods in spring-core to make the AOP specific support discoverable via the core user API.
If that is so important this was discussed, I'd like us to review RuntimeHintsUtils#registerAnnotation
.
Comment From: sbrannen
If that is so important this was discussed, I'd like us to review
RuntimeHintsUtils#registerAnnotation
.
Do you mean you'd like to cross reference RuntimeHintsUtils
from ProxyHints
?
If so, I agree that that's a good idea.
In any case, feel free to bring it up in the team or open an issue to discuss what you'd like to review.
Comment From: sbrannen
Reopening to reduce the scope of this feature to Class
references.