|
|
|
@ -26,7 +26,10 @@ import java.util.Set;
|
|
|
|
|
import org.springframework.beans.BeansException;
|
|
|
|
|
import org.springframework.beans.factory.BeanFactory;
|
|
|
|
|
import org.springframework.beans.factory.BeanFactoryAware;
|
|
|
|
|
import org.springframework.beans.factory.BeanFactoryUtils;
|
|
|
|
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
|
|
|
|
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
|
|
|
|
|
import org.springframework.beans.factory.config.BeanDefinition;
|
|
|
|
|
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport;
|
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport.ConditionAndOutcome;
|
|
|
|
@ -78,18 +81,27 @@ class NoSuchBeanDefinitionFailureAnalyzer
|
|
|
|
|
}
|
|
|
|
|
List<AutoConfigurationResult> autoConfigurationResults = getAutoConfigurationResults(
|
|
|
|
|
cause);
|
|
|
|
|
List<UserConfigurationResult> userConfigurationResults = getUserConfigurationResults(
|
|
|
|
|
cause);
|
|
|
|
|
StringBuilder message = new StringBuilder();
|
|
|
|
|
message.append(String.format("%s required %s that could not be found.%n",
|
|
|
|
|
(description != null ? description : "A component"),
|
|
|
|
|
getBeanDescription(cause)));
|
|
|
|
|
if (!autoConfigurationResults.isEmpty()) {
|
|
|
|
|
for (AutoConfigurationResult provider : autoConfigurationResults) {
|
|
|
|
|
message.append(String.format("\t- %s%n", provider));
|
|
|
|
|
for (AutoConfigurationResult result : autoConfigurationResults) {
|
|
|
|
|
message.append(String.format("\t- %s%n", result));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!userConfigurationResults.isEmpty()) {
|
|
|
|
|
for (UserConfigurationResult result : userConfigurationResults) {
|
|
|
|
|
message.append(String.format("\t- %s%n", result));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
String action = String.format("Consider %s %s in your configuration.",
|
|
|
|
|
(!autoConfigurationResults.isEmpty()
|
|
|
|
|
? "revisiting the conditions above or defining" : "defining"),
|
|
|
|
|
|| !userConfigurationResults.isEmpty()
|
|
|
|
|
? "revisiting the entries above or defining"
|
|
|
|
|
: "defining"),
|
|
|
|
|
getBeanDescription(cause));
|
|
|
|
|
return new FailureAnalysis(message.toString(), action, cause);
|
|
|
|
|
}
|
|
|
|
@ -122,6 +134,30 @@ class NoSuchBeanDefinitionFailureAnalyzer
|
|
|
|
|
return results;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<UserConfigurationResult> getUserConfigurationResults(
|
|
|
|
|
NoSuchBeanDefinitionException cause) {
|
|
|
|
|
List<UserConfigurationResult> results = new ArrayList<>();
|
|
|
|
|
ResolvableType type = cause.getResolvableType();
|
|
|
|
|
if (type != null) {
|
|
|
|
|
for (String beanName : BeanFactoryUtils.beanNamesForTypeIncludingAncestors(
|
|
|
|
|
this.beanFactory, cause.getResolvableType())) {
|
|
|
|
|
boolean nullBean = this.beanFactory.getBean(beanName).equals(null);
|
|
|
|
|
results.add(new UserConfigurationResult(
|
|
|
|
|
getFactoryMethodMetadata(beanName), nullBean));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return results;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MethodMetadata getFactoryMethodMetadata(String beanName) {
|
|
|
|
|
BeanDefinition beanDefinition = this.beanFactory.getBeanDefinition(beanName);
|
|
|
|
|
if (beanDefinition instanceof AnnotatedBeanDefinition) {
|
|
|
|
|
return ((AnnotatedBeanDefinition) beanDefinition).getFactoryMethodMetadata();
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void collectReportedConditionOutcomes(NoSuchBeanDefinitionException cause,
|
|
|
|
|
List<AutoConfigurationResult> results) {
|
|
|
|
|
this.report.getConditionAndOutcomesBySource().forEach(
|
|
|
|
@ -296,4 +332,31 @@ class NoSuchBeanDefinitionFailureAnalyzer
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static class UserConfigurationResult {
|
|
|
|
|
|
|
|
|
|
private final MethodMetadata methodMetadata;
|
|
|
|
|
|
|
|
|
|
private final boolean nullBean;
|
|
|
|
|
|
|
|
|
|
UserConfigurationResult(MethodMetadata methodMetadata, boolean nullBean) {
|
|
|
|
|
this.methodMetadata = methodMetadata;
|
|
|
|
|
this.nullBean = nullBean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String toString() {
|
|
|
|
|
StringBuilder sb = new StringBuilder("User-defined bean");
|
|
|
|
|
if (this.methodMetadata != null) {
|
|
|
|
|
sb.append(String.format(" method '%s' in '%s'",
|
|
|
|
|
this.methodMetadata.getMethodName(), ClassUtils.getShortName(
|
|
|
|
|
this.methodMetadata.getDeclaringClassName())));
|
|
|
|
|
}
|
|
|
|
|
if (this.nullBean) {
|
|
|
|
|
sb.append(" ignored as the bean value is null");
|
|
|
|
|
}
|
|
|
|
|
return sb.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|