|
34 | 34 | import org.springframework.beans.factory.ListableBeanFactory;
|
35 | 35 | import org.springframework.beans.factory.config.BeanDefinition;
|
36 | 36 | import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
| 37 | +import org.springframework.boot.autoconfigure.AutoConfigurationMetadata; |
37 | 38 | import org.springframework.boot.autoconfigure.condition.ConditionMessage.Style;
|
38 | 39 | import org.springframework.context.annotation.Bean;
|
39 | 40 | import org.springframework.context.annotation.Condition;
|
|
58 | 59 | * @author Andy Wilkinson
|
59 | 60 | */
|
60 | 61 | @Order(Ordered.LOWEST_PRECEDENCE)
|
61 |
| -class OnBeanCondition extends SpringBootCondition implements ConfigurationCondition { |
| 62 | +class OnBeanCondition extends FilteringSpringBootCondition |
| 63 | + implements ConfigurationCondition { |
62 | 64 |
|
63 | 65 | /**
|
64 | 66 | * Bean definition attribute name for factory beans to signal their product type (if
|
65 | 67 | * known and it can't be deduced from the factory bean class).
|
66 | 68 | */
|
67 | 69 | public static final String FACTORY_BEAN_OBJECT_TYPE = BeanTypeRegistry.FACTORY_BEAN_OBJECT_TYPE;
|
68 | 70 |
|
| 71 | + @Override |
| 72 | + protected final ConditionOutcome[] getOutcomes(String[] autoConfigurationClasses, |
| 73 | + AutoConfigurationMetadata autoConfigurationMetadata) { |
| 74 | + ConditionOutcome[] outcomes = new ConditionOutcome[autoConfigurationClasses.length]; |
| 75 | + for (int i = 0; i < outcomes.length; i++) { |
| 76 | + String autoConfigurationClass = autoConfigurationClasses[i]; |
| 77 | + if (autoConfigurationClass != null) { |
| 78 | + Set<String> onBeanTypes = autoConfigurationMetadata |
| 79 | + .getSet(autoConfigurationClass, "ConditionalOnBean"); |
| 80 | + outcomes[i] = getOutcome(onBeanTypes, ConditionalOnBean.class); |
| 81 | + if (outcomes[i] == null) { |
| 82 | + Set<String> onSingleCandidateTypes = autoConfigurationMetadata.getSet( |
| 83 | + autoConfigurationClass, "ConditionalOnSingleCandidate"); |
| 84 | + outcomes[i] = getOutcome(onSingleCandidateTypes, |
| 85 | + ConditionalOnSingleCandidate.class); |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | + return outcomes; |
| 90 | + } |
| 91 | + |
| 92 | + private ConditionOutcome getOutcome(Set<String> requiredBeanTypes, |
| 93 | + Class<? extends Annotation> annotation) { |
| 94 | + List<String> missing = filter(requiredBeanTypes, ClassNameFilter.MISSING, |
| 95 | + getBeanClassLoader()); |
| 96 | + if (!missing.isEmpty()) { |
| 97 | + ConditionMessage message = ConditionMessage.forCondition(annotation) |
| 98 | + .didNotFind("required type", "required types") |
| 99 | + .items(Style.QUOTE, missing); |
| 100 | + return ConditionOutcome.noMatch(message); |
| 101 | + } |
| 102 | + return null; |
| 103 | + } |
| 104 | + |
69 | 105 | @Override
|
70 | 106 | public ConfigurationPhase getConfigurationPhase() {
|
71 | 107 | return ConfigurationPhase.REGISTER_BEAN;
|
@@ -337,7 +373,6 @@ private BeanDefinition findBeanDefinition(ConfigurableListableBeanFactory beanFa
|
337 | 373 | .getParentBeanFactory()), beanName, considerHierarchy);
|
338 | 374 | }
|
339 | 375 | return null;
|
340 |
| - |
341 | 376 | }
|
342 | 377 |
|
343 | 378 | private static class BeanSearchSpec {
|
|
0 commit comments