Make constructorOrFactory method resolution optional

This commit allows a custom code fragment to provide the code to
create a bean without relying on ConstructorResolver. This is especially
important for use cases that derive from the default behaviour and
provide an instance supplier with the regular runtime scenario.

This is a breaking change for code fragments providing a custom
implementation of the related methods. As it turns out, almost all of
them did not need the Executable argument. Configuration class parsing
is the exception, where it needs to provide a different constructor in
the case of the proxy. To make this use case possible,
InstanceSupplierCodeGenerator has been made public.

Closes gh-31117
This commit is contained in:
Stephane Nicoll
2023-09-11 09:47:44 +02:00
parent fceed9f3e5
commit 66a571fe27
10 changed files with 260 additions and 163 deletions

View File

@@ -16,7 +16,6 @@
package org.springframework.aop.scope;
import java.lang.reflect.Executable;
import java.util.function.Predicate;
import javax.lang.model.element.Modifier;
@@ -109,7 +108,7 @@ class ScopedProxyBeanRegistrationAotProcessor implements BeanRegistrationAotProc
}
@Override
public ClassName getTarget(RegisteredBean registeredBean, Executable constructorOrFactoryMethod) {
public ClassName getTarget(RegisteredBean registeredBean) {
return ClassName.get(this.targetBeanDefinition.getResolvableType().toClass());
}
@@ -139,9 +138,7 @@ class ScopedProxyBeanRegistrationAotProcessor implements BeanRegistrationAotProc
@Override
public CodeBlock generateInstanceSupplierCode(GenerationContext generationContext,
BeanRegistrationCode beanRegistrationCode,
Executable constructorOrFactoryMethod,
boolean allowDirectSupplierShortcut) {
BeanRegistrationCode beanRegistrationCode, boolean allowDirectSupplierShortcut) {
GeneratedMethod generatedMethod = beanRegistrationCode.getMethods()
.add("getScopedProxyInstance", method -> {