Bean Class — spring-boot Architecture
Architecture documentation for the Bean class in JavaBeanBinder.java from the spring-boot codebase.
Entity Profile
Relationship Graph
Source Code
core/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/JavaBeanBinder.java lines 263–333
static class Bean<T> extends BeanProperties {
Bean(ResolvableType type, Class<?> resolvedType) {
super(type, resolvedType);
}
@SuppressWarnings("unchecked")
BeanSupplier<T> getSupplier(Bindable<T> target) {
return new BeanSupplier<>(() -> {
T instance = null;
if (target.getValue() != null) {
instance = target.getValue().get();
}
if (instance == null) {
instance = (T) BeanUtils.instantiateClass(getResolvedType());
}
return instance;
});
}
@SuppressWarnings("unchecked")
static <T> @Nullable Bean<T> get(Bindable<T> bindable, Context context, boolean canCallGetValue) {
ResolvableType type = bindable.getType();
Class<?> resolvedType = type.resolve(Object.class);
Supplier<T> value = bindable.getValue();
T instance = null;
if (canCallGetValue && value != null) {
instance = value.get();
resolvedType = (instance != null) ? instance.getClass() : resolvedType;
}
if (instance == null && !isInstantiable(resolvedType)) {
return null;
}
Map<CacheKey, Bean<?>> cache = getCache(context);
CacheKey cacheKey = new CacheKey(type, resolvedType);
Bean<?> bean = cache.get(cacheKey);
if (bean == null) {
bean = new Bean<>(type, resolvedType);
cache.put(cacheKey, bean);
}
return (Bean<T>) bean;
}
@SuppressWarnings("unchecked")
private static Map<CacheKey, Bean<?>> getCache(Context context) {
Map<CacheKey, Bean<?>> cache = (Map<CacheKey, Bean<?>>) context.getCache().get(Bean.class);
if (cache == null) {
cache = new ConcurrentHashMap<>();
context.getCache().put(Bean.class, cache);
}
return cache;
}
private static boolean isInstantiable(Class<?> type) {
if (type.isInterface()) {
return false;
}
try {
type.getDeclaredConstructor();
return true;
}
catch (Exception ex) {
return false;
}
}
private record CacheKey(ResolvableType type, Class<?> resolvedType) {
}
}
Domain
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free