Introduce @Proxyable annotation for bean-specific proxy type

Closes gh-35296
See gh-35293
This commit is contained in:
Juergen Hoeller
2025-08-06 18:26:40 +02:00
parent 9edb96ae57
commit df86a9973d
8 changed files with 175 additions and 22 deletions
@@ -22,6 +22,7 @@ import java.util.function.Predicate;
import org.jspecify.annotations.Nullable;
import org.springframework.aop.framework.autoproxy.AutoProxyUtils;
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor;
import org.springframework.beans.factory.config.BeanDefinition;
@@ -258,6 +259,20 @@ public abstract class AnnotationConfigUtils {
if (description != null) {
abd.setDescription(description.getString("value"));
}
AnnotationAttributes proxyable = attributesFor(metadata, Proxyable.class);
if (proxyable != null) {
ProxyType mode = proxyable.getEnum("value");
if (mode == ProxyType.TARGET_CLASS) {
abd.setAttribute(AutoProxyUtils.PRESERVE_TARGET_CLASS_ATTRIBUTE, Boolean.TRUE);
}
else {
Class<?>[] ifcs = proxyable.getClassArray("interfaces");
if (ifcs.length > 0 || mode == ProxyType.INTERFACES) {
abd.setAttribute(AutoProxyUtils.EXPOSED_INTERFACES_ATTRIBUTE, ifcs);
}
}
}
}
static BeanDefinitionHolder applyScopedProxyMode(