From affccba8f1beccdb5910e4a0e909701d33255db5 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 19 Oct 2022 16:58:16 +0200 Subject: [PATCH] Simplify AOT contribution for scoped proxies This commit makes sure that a `ScopedProxyFactoryBean` is exposed in the container, rather than its underlying proxy. Previously, any lifecycle method that the proxy target exposed were invoked in the container. This is a complementary fix to gh-29335 --- .../aop/scope/ScopedProxyBeanRegistrationAotProcessor.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyBeanRegistrationAotProcessor.java b/spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyBeanRegistrationAotProcessor.java index 305b71ef46..7f71d3a3fc 100644 --- a/spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyBeanRegistrationAotProcessor.java +++ b/spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyBeanRegistrationAotProcessor.java @@ -145,13 +145,11 @@ class ScopedProxyBeanRegistrationAotProcessor implements BeanRegistrationAotProc GeneratedMethod generatedMethod = beanRegistrationCode.getMethods() .add("getScopedProxyInstance", method -> { - Class beanClass = this.targetBeanDefinition.getResolvableType() - .toClass(); method.addJavadoc( "Create the scoped proxy bean instance for '$L'.", this.registeredBean.getBeanName()); method.addModifiers(Modifier.PRIVATE, Modifier.STATIC); - method.returns(beanClass); + method.returns(ScopedProxyFactoryBean.class); method.addParameter(RegisteredBean.class, REGISTERED_BEAN_PARAMETER_NAME); method.addStatement("$T factory = new $T()", @@ -162,8 +160,7 @@ class ScopedProxyBeanRegistrationAotProcessor implements BeanRegistrationAotProc method.addStatement( "factory.setBeanFactory($L.getBeanFactory())", REGISTERED_BEAN_PARAMETER_NAME); - method.addStatement("return ($T) factory.getObject()", - beanClass); + method.addStatement("return factory"); }); return CodeBlock.of("$T.of($L)", InstanceSupplier.class, generatedMethod.toMethodReference().toCodeBlock());