Make use of Executable abstraction in ProxyRuntimeHintsRegistrar
This commit is contained in:
parent
911d1b03cd
commit
2569aa157e
|
@ -151,12 +151,7 @@ public class InstanceSupplierCodeGenerator {
|
|||
if (registeredBean.getBeanFactory() instanceof DefaultListableBeanFactory dlbf) {
|
||||
RuntimeHints runtimeHints = this.generationContext.getRuntimeHints();
|
||||
ProxyRuntimeHintsRegistrar registrar = new ProxyRuntimeHintsRegistrar(dlbf.getAutowireCandidateResolver());
|
||||
if (constructorOrFactoryMethod instanceof Method method) {
|
||||
registrar.registerRuntimeHints(runtimeHints, method);
|
||||
}
|
||||
else if (constructorOrFactoryMethod instanceof Constructor<?> constructor) {
|
||||
registrar.registerRuntimeHints(runtimeHints, constructor);
|
||||
}
|
||||
registrar.registerRuntimeHints(runtimeHints, constructorOrFactoryMethod);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -419,33 +414,17 @@ public class InstanceSupplierCodeGenerator {
|
|||
}
|
||||
|
||||
|
||||
private static class ProxyRuntimeHintsRegistrar {
|
||||
private record ProxyRuntimeHintsRegistrar(AutowireCandidateResolver candidateResolver) {
|
||||
|
||||
private final AutowireCandidateResolver candidateResolver;
|
||||
|
||||
public ProxyRuntimeHintsRegistrar(AutowireCandidateResolver candidateResolver) {
|
||||
this.candidateResolver = candidateResolver;
|
||||
}
|
||||
|
||||
public void registerRuntimeHints(RuntimeHints runtimeHints, Method method) {
|
||||
Class<?>[] parameterTypes = method.getParameterTypes();
|
||||
public void registerRuntimeHints(RuntimeHints runtimeHints, Executable executable) {
|
||||
Class<?>[] parameterTypes = executable.getParameterTypes();
|
||||
for (int i = 0; i < parameterTypes.length; i++) {
|
||||
MethodParameter methodParam = new MethodParameter(method, i);
|
||||
MethodParameter methodParam = MethodParameter.forExecutable(executable, i);
|
||||
DependencyDescriptor dependencyDescriptor = new DependencyDescriptor(methodParam, true);
|
||||
registerProxyIfNecessary(runtimeHints, dependencyDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
public void registerRuntimeHints(RuntimeHints runtimeHints, Constructor<?> constructor) {
|
||||
Class<?>[] parameterTypes = constructor.getParameterTypes();
|
||||
for (int i = 0; i < parameterTypes.length; i++) {
|
||||
MethodParameter methodParam = new MethodParameter(constructor, i);
|
||||
DependencyDescriptor dependencyDescriptor = new DependencyDescriptor(
|
||||
methodParam, true);
|
||||
registerProxyIfNecessary(runtimeHints, dependencyDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
private void registerProxyIfNecessary(RuntimeHints runtimeHints, DependencyDescriptor dependencyDescriptor) {
|
||||
Class<?> proxyType = this.candidateResolver.getLazyResolutionProxyClass(dependencyDescriptor, null);
|
||||
if (proxyType != null && Proxy.isProxyClass(proxyType)) {
|
||||
|
|
Loading…
Reference in New Issue