Revisit BeanRegistrationCodeFragments

This commit revisit BeanRegistrationCodeFragments to separate the
responsibility between the default implementation and the delegates. It
also reviews how customization are applied by improving the Javadoc and
the method name.

Closes gh-28865
This commit is contained in:
Stephane Nicoll
2022-09-22 15:32:28 +02:00
parent ef5b64dc00
commit c19cedede1
7 changed files with 150 additions and 84 deletions

View File

@@ -30,6 +30,7 @@ import org.springframework.beans.factory.aot.BeanRegistrationAotContribution;
import org.springframework.beans.factory.aot.BeanRegistrationAotProcessor;
import org.springframework.beans.factory.aot.BeanRegistrationCode;
import org.springframework.beans.factory.aot.BeanRegistrationCodeFragments;
import org.springframework.beans.factory.aot.BeanRegistrationCodeFragmentsDecorator;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.beans.factory.support.InstanceSupplier;
@@ -63,9 +64,9 @@ class ScopedProxyBeanRegistrationAotProcessor implements BeanRegistrationAotProc
": no target bean definition found with name " + targetBeanName);
return null;
}
return BeanRegistrationAotContribution.ofBeanRegistrationCodeFragmentsCustomizer(codeFragments ->
new ScopedProxyBeanRegistrationCodeFragments(codeFragments, registeredBean,
targetBeanName, targetBeanDefinition));
return BeanRegistrationAotContribution.withCustomCodeFragments(codeFragments ->
new ScopedProxyBeanRegistrationCodeFragments(codeFragments, registeredBean,
targetBeanName, targetBeanDefinition));
}
return null;
}
@@ -87,7 +88,7 @@ class ScopedProxyBeanRegistrationAotProcessor implements BeanRegistrationAotProc
}
private static class ScopedProxyBeanRegistrationCodeFragments extends BeanRegistrationCodeFragments {
private static class ScopedProxyBeanRegistrationCodeFragments extends BeanRegistrationCodeFragmentsDecorator {
private static final String REGISTERED_BEAN_PARAMETER_NAME = "registeredBean";
@@ -97,10 +98,10 @@ class ScopedProxyBeanRegistrationAotProcessor implements BeanRegistrationAotProc
private final BeanDefinition targetBeanDefinition;
ScopedProxyBeanRegistrationCodeFragments(BeanRegistrationCodeFragments codeGenerator,
ScopedProxyBeanRegistrationCodeFragments(BeanRegistrationCodeFragments delegate,
RegisteredBean registeredBean, String targetBeanName, BeanDefinition targetBeanDefinition) {
super(codeGenerator);
super(delegate);
this.registeredBean = registeredBean;
this.targetBeanName = targetBeanName;
this.targetBeanDefinition = targetBeanDefinition;