Avoid double proxying for @Resource @Lazy fallback autowiring

Includes refactored @Resource resolver for AOT with lazy resolution support.

Closes gh-31447
See gh-29614
This commit is contained in:
Juergen Hoeller
2023-12-12 12:39:59 +01:00
parent 6bb9775309
commit 6dcba4de2c
11 changed files with 410 additions and 457 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -375,6 +375,16 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable
}
}
/**
* Determine whether this dependency supports lazy resolution,
* e.g. through extra proxying. The default is {@code true}.
* @since 6.1.2
* @see org.springframework.beans.factory.support.AutowireCandidateResolver#getLazyResolutionProxyIfNecessary
*/
public boolean supportsLazyResolution() {
return true;
}
@Override
public boolean equals(@Nullable Object other) {

View File

@@ -1343,14 +1343,14 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
else if (javaxInjectProviderClass == descriptor.getDependencyType()) {
return new Jsr330Factory().createDependencyProvider(descriptor, requestingBeanName);
}
else {
else if (descriptor.supportsLazyResolution()) {
Object result = getAutowireCandidateResolver().getLazyResolutionProxyIfNecessary(
descriptor, requestingBeanName);
if (result == null) {
result = doResolveDependency(descriptor, requestingBeanName, autowiredBeanNames, typeConverter);
if (result != null) {
return result;
}
return result;
}
return doResolveDependency(descriptor, requestingBeanName, autowiredBeanNames, typeConverter);
}
@Nullable