mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-18 04:29:11 +00:00
Check scoped proxy target for isDefaultCandidate
Update `OnBeanCondition` to check the scoped proxy target for `isDefaultCandidate`. This fixes an issue introduced by https://github.com/spring-projects/spring-framework/pull/35627. Fixes gh-47633
This commit is contained in:
+16
-15
@@ -270,23 +270,24 @@ class OnBeanCondition extends FilteringSpringBootCondition implements Configurat
|
||||
|
||||
private boolean isCandidate(ConfigurableListableBeanFactory beanFactory, String name, BeanDefinition definition,
|
||||
Set<String> ignoredBeans) {
|
||||
return (!ignoredBeans.contains(name)) && (definition == null
|
||||
|| isAutowireCandidate(beanFactory, name, definition) && isDefaultCandidate(definition));
|
||||
}
|
||||
|
||||
private boolean isAutowireCandidate(ConfigurableListableBeanFactory beanFactory, String name,
|
||||
BeanDefinition definition) {
|
||||
return definition.isAutowireCandidate() || isScopeTargetAutowireCandidate(beanFactory, name);
|
||||
}
|
||||
|
||||
private boolean isScopeTargetAutowireCandidate(ConfigurableListableBeanFactory beanFactory, String name) {
|
||||
try {
|
||||
return ScopedProxyUtils.isScopedTarget(name)
|
||||
&& beanFactory.getBeanDefinition(ScopedProxyUtils.getOriginalBeanName(name)).isAutowireCandidate();
|
||||
}
|
||||
catch (NoSuchBeanDefinitionException ex) {
|
||||
if (ignoredBeans.contains(name) || definition == null) {
|
||||
return false;
|
||||
}
|
||||
if (definition.isAutowireCandidate() && isDefaultCandidate(definition)) {
|
||||
return true;
|
||||
}
|
||||
if (ScopedProxyUtils.isScopedTarget(name)) {
|
||||
try {
|
||||
BeanDefinition originalDefinition = beanFactory
|
||||
.getBeanDefinition(ScopedProxyUtils.getOriginalBeanName(name));
|
||||
if (originalDefinition.isAutowireCandidate() && isDefaultCandidate(originalDefinition)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (NoSuchBeanDefinitionException ex) {
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isDefaultCandidate(BeanDefinition definition) {
|
||||
|
||||
Reference in New Issue
Block a user