BeanMethods Class — spring-boot Architecture
Architecture documentation for the BeanMethods class in NoSuchBeanDefinitionFailureAnalyzer.java from the spring-boot codebase.
Entity Profile
Relationship Graph
Source Code
core/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/diagnostics/analyzer/NoSuchBeanDefinitionFailureAnalyzer.java lines 222–293
private class BeanMethods implements Iterable<MethodMetadata> {
private final List<MethodMetadata> methods;
BeanMethods(Source source, NoSuchBeanDefinitionException cause) {
this.methods = findBeanMethods(source, cause);
}
private List<MethodMetadata> findBeanMethods(Source source, NoSuchBeanDefinitionException cause) {
try {
MetadataReader classMetadata = NoSuchBeanDefinitionFailureAnalyzer.this.metadataReaderFactory
.getMetadataReader(source.getClassName());
Set<MethodMetadata> candidates = classMetadata.getAnnotationMetadata()
.getAnnotatedMethods(Bean.class.getName());
List<MethodMetadata> result = new ArrayList<>();
for (MethodMetadata candidate : candidates) {
if (isMatch(candidate, source, cause)) {
result.add(candidate);
}
}
return Collections.unmodifiableList(result);
}
catch (Exception ex) {
return Collections.emptyList();
}
}
private boolean isMatch(MethodMetadata candidate, Source source, NoSuchBeanDefinitionException cause) {
if (source.getMethodName() != null && !source.getMethodName().equals(candidate.getMethodName())) {
return false;
}
String name = cause.getBeanName();
ResolvableType resolvableType = cause.getResolvableType();
return ((name != null && hasName(candidate, name))
|| (resolvableType != null && hasType(candidate, extractBeanType(resolvableType))));
}
private boolean hasName(MethodMetadata methodMetadata, String name) {
Map<String, @Nullable Object> attributes = methodMetadata.getAnnotationAttributes(Bean.class.getName());
String[] candidates = (attributes != null) ? (String[]) attributes.get("name") : null;
if (candidates != null) {
for (String candidate : candidates) {
if (candidate.equals(name)) {
return true;
}
}
return false;
}
return methodMetadata.getMethodName().equals(name);
}
private boolean hasType(MethodMetadata candidate, Class<?> type) {
String returnTypeName = candidate.getReturnTypeName();
if (type.getName().equals(returnTypeName)) {
return true;
}
try {
Class<?> returnType = ClassUtils.forName(returnTypeName,
NoSuchBeanDefinitionFailureAnalyzer.this.beanFactory.getBeanClassLoader());
return type.isAssignableFrom(returnType);
}
catch (Throwable ex) {
return false;
}
}
@Override
public Iterator<MethodMetadata> iterator() {
return this.methods.iterator();
}
}
Domain
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free