Skip to content

Commit

Permalink
Simplify AOT contribution for scoped proxies
Browse files Browse the repository at this point in the history
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
  • Loading branch information
snicoll committed Oct 19, 2022
1 parent 7f1990e commit affccba
Showing 1 changed file with 2 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,11 @@ public CodeBlock generateInstanceSupplierCode(GenerationContext generationContex

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()",
Expand All @@ -162,8 +160,7 @@ public CodeBlock generateInstanceSupplierCode(GenerationContext generationContex
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());
Expand Down

0 comments on commit affccba

Please sign in to comment.