|
17 | 17 | package org.springframework.boot.autoconfigure.diagnostics.analyzer; |
18 | 18 |
|
19 | 19 | import java.util.ArrayList; |
| 20 | +import java.util.Arrays; |
20 | 21 | import java.util.Collections; |
21 | 22 | import java.util.Iterator; |
22 | 23 | import java.util.List; |
23 | 24 | import java.util.Map; |
24 | 25 | import java.util.Set; |
| 26 | +import java.util.stream.Collectors; |
25 | 27 |
|
26 | 28 | import org.springframework.beans.BeansException; |
27 | 29 | import org.springframework.beans.factory.BeanFactory; |
@@ -87,15 +89,11 @@ protected FailureAnalysis analyze(Throwable rootFailure, |
87 | 89 | message.append(String.format("%s required %s that could not be found.%n", |
88 | 90 | (description != null ? description : "A component"), |
89 | 91 | getBeanDescription(cause))); |
90 | | - if (!autoConfigurationResults.isEmpty()) { |
91 | | - for (AutoConfigurationResult result : autoConfigurationResults) { |
92 | | - message.append(String.format("\t- %s%n", result)); |
93 | | - } |
| 92 | + for (AutoConfigurationResult result : autoConfigurationResults) { |
| 93 | + message.append(String.format("\t- %s%n", result)); |
94 | 94 | } |
95 | | - if (!userConfigurationResults.isEmpty()) { |
96 | | - for (UserConfigurationResult result : userConfigurationResults) { |
97 | | - message.append(String.format("\t- %s%n", result)); |
98 | | - } |
| 95 | + for (UserConfigurationResult result : userConfigurationResults) { |
| 96 | + message.append(String.format("\t- %s%n", result)); |
99 | 97 | } |
100 | 98 | String action = String.format("Consider %s %s in your configuration.", |
101 | 99 | (!autoConfigurationResults.isEmpty() |
@@ -136,18 +134,17 @@ private List<AutoConfigurationResult> getAutoConfigurationResults( |
136 | 134 |
|
137 | 135 | private List<UserConfigurationResult> getUserConfigurationResults( |
138 | 136 | NoSuchBeanDefinitionException cause) { |
139 | | - List<UserConfigurationResult> results = new ArrayList<>(); |
140 | 137 | ResolvableType type = cause.getResolvableType(); |
141 | | - if (type != null) { |
142 | | - for (String beanName : BeanFactoryUtils.beanNamesForTypeIncludingAncestors( |
143 | | - this.beanFactory, cause.getResolvableType())) { |
144 | | - boolean nullBean = this.beanFactory.getBean(beanName).equals(null); |
145 | | - results.add(new UserConfigurationResult( |
146 | | - getFactoryMethodMetadata(beanName), nullBean)); |
147 | | - } |
| 138 | + if (type == null) { |
| 139 | + return Collections.emptyList(); |
148 | 140 | } |
149 | | - return results; |
150 | | - |
| 141 | + String[] beanNames = BeanFactoryUtils |
| 142 | + .beanNamesForTypeIncludingAncestors(this.beanFactory, type); |
| 143 | + return Arrays.stream(beanNames) |
| 144 | + .map((beanName) -> new UserConfigurationResult( |
| 145 | + getFactoryMethodMetadata(beanName), |
| 146 | + this.beanFactory.getBean(beanName).equals(null))) |
| 147 | + .collect(Collectors.toList()); |
151 | 148 | } |
152 | 149 |
|
153 | 150 | private MethodMetadata getFactoryMethodMetadata(String beanName) { |
|
0 commit comments