Add support for @Transactional in native images

This commit introduces a TransactionBeanRegistrationAotProcessor
in charge of creating the required proxy and reflection hints
when @Transactional is detected on beans.

It also refines DefaultAopProxyFactory to throw an exception
when a subclass-based proxy is created in native images
since that's unsupported for now (see gh-28115 related issue).

Closes gh-28717
This commit is contained in:
Sébastien Deleuze
2022-07-08 15:43:14 +02:00
parent a64d3716e0
commit 1458d5f39f
5 changed files with 283 additions and 2 deletions

View File

@@ -54,8 +54,7 @@ public class DefaultAopProxyFactory implements AopProxyFactory, Serializable {
@Override
public AopProxy createAopProxy(AdvisedSupport config) throws AopConfigException {
if (!NativeDetector.inNativeImage() &&
(config.isOptimize() || config.isProxyTargetClass() || hasNoUserSuppliedProxyInterfaces(config))) {
if (config.isOptimize() || config.isProxyTargetClass() || hasNoUserSuppliedProxyInterfaces(config)) {
Class<?> targetClass = config.getTargetClass();
if (targetClass == null) {
throw new AopConfigException("TargetSource cannot determine target class: " +
@@ -64,6 +63,9 @@ public class DefaultAopProxyFactory implements AopProxyFactory, Serializable {
if (targetClass.isInterface() || Proxy.isProxyClass(targetClass) || ClassUtils.isLambdaClass(targetClass)) {
return new JdkDynamicAopProxy(config);
}
if (NativeDetector.inNativeImage()) {
throw new AopConfigException("Subclass-based proxies are not support yet in native images");
}
return new ObjenesisCglibAopProxy(config);
}
else {