/**
* Spring's default implementation of the {@link ConfigurableListableBeanFactory} Spring 对 ConfigurableListableBeanFactory 和 BeanDefinitionRegistry
* and {@link BeanDefinitionRegistry} interfaces: a full-fledged bean factory 的默认实现:一个基于 bean definition 元数据,
* based on bean definition metadata, extensible through post-processors. 可以通过 post-processors 扩展成熟的 bean factory
*
* <p>Typical usage is registering all bean definitions first (possibly read 典型的用法是在访问 bean 之前首先注册所有的 bean definitions (可能从 bean definition 中去读取)
* from a bean definition file), before accessing beans. Bean lookup by name 凭借名字查找 bean 是昂贵的,因此从本地 bean definition 表中查找
* is therefore an inexpensive operation in a local bean definition table,
* operating on pre-resolved bean definition metadata objects. 从预解析的 bean definition 元数据对象上操作
*
* <p>Note that readers for specific bean definition formats are typically 注意阅读指定的 bean definition 的通用格式是通常是单独出现
* implemented separately rather than as bean factory subclasses: see for example 而不是伴随着 bean factroy 的子类实现:例如 XmlBeanDefinitionReader
* {@link org.springframework.beans.factory.xml.XmlBeanDefinitionReader}.
*
* <p>For an alternative implementation of the
* {@link org.springframework.beans.factory.ListableBeanFactory} interface, 用于替代 ListableBeanFactory 实现的接口,
* have a look at {@link StaticListableBeanFactory}, which manages existing 可以看看 StaticListableBeanFactory,
* bean instances rather than creating new ones based on bean definitions. 它管理现有的 bean 实例,而不是创建新的
*
* @author Rod Johnson
* @author Juergen Hoeller
* @author Sam Brannen
* @author Costin Leau
* @author Chris Beams
* @author Phillip Webb
* @author Stephane Nicoll
* @since 16 April 2001
* @see #registerBeanDefinition
* @see #addBeanPostProcessor
* @see #getBean
* @see #resolveDependency
*/
@SuppressWarnings("serial")
public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFactory
implements ConfigurableListableBeanFactory, BeanDefinitionRegistry, Serializable {
@Nullable
private static Class<?> javaxInjectProviderClass;
static {
try {
javaxInjectProviderClass =
ClassUtils.forName("javax.inject.Provider", DefaultListableBeanFactory.class.getClassLoader());
}
catch (ClassNotFoundException ex) {
// JSR-330 API not available - Provider interface simply not supported then.
javaxInjectProviderClass = null;
}
}
/** Map from serialized id to factory instance. (序列化 id, 工厂实例)*/
private static final Map<String, Reference<DefaultListableBeanFactory>> serializableFactories =
new ConcurrentHashMap<>(8);
/** Optional id for this factory, for serialization purposes. */
@Nullable
private String serializationId;
/** Whether to allow re-registration of a different definition with the same name. */
private boolean allowBeanDefinitionOverriding = true;
/** Whether to allow eager class loading even for lazy-init beans. */
private boolean allowEagerClassLoading = true;
/** Optional OrderComparator for dependency Lists and arrays. 用于依赖列表和数组的顺序比较器*/
@Nullable
private Comparator<Object> dependencyComparator;
/** Resolver to use for checking if a bean definition is an autowire candidate. 用于检查 bean definition 是否为候选 candidate 的解析器*/
private AutowireCandidateResolver autowireCandidateResolver = new SimpleAutowireCandidateResolver();
/** Map from dependency type to corresponding autowired value. (依赖的类型,对应的实体)*/
private final Map<Class<?>, Object> resolvableDependencies = new ConcurrentHashMap<>(16);
/** Map of bean definition objects, keyed by bean name. (bean name,BeanDefinition)*/
private final Map<String, BeanDefinition> beanDefinitionMap = new ConcurrentHashMap<>(256);
/** Map from bean name to merged BeanDefinitionHolder. (bean name,被合并过后的 BeanDefinitionHolder)*/
private final Map<String, BeanDefinitionHolder> mergedBeanDefinitionHolders = new ConcurrentHashMap<>(256);
/** Map of singleton and non-singleton bean names, keyed by dependency type. (类型,单例和非单例的 bean name)*/
private final Map<Class<?>, String[]> allBeanNamesByType = new ConcurrentHashMap<>(64);
/** Map of singleton-only bean names, keyed by dependency type. (类型,仅单例 bean 的名字)*/
private final Map<Class<?>, String[]> singletonBeanNamesByType = new ConcurrentHashMap<>(64);
/** List of bean definition names, in registration order. bean definition 的名字列表,按照注册顺序排序*/
private volatile List<String> beanDefinitionNames = new ArrayList<>(256);
/** List of names of manually registered singletons, in registration order. 在按照顺序注册中,手动注册的单例列表*/
private volatile Set<String> manualSingletonNames = new LinkedHashSet<>(16);
/** Cached array of bean definition names in case of frozen configuration. 冻结 bean definition names 的缓存数组 */
@Nullable
private volatile String[] frozenBeanDefinitionNames;
/** Whether bean definition metadata may be cached for all beans. */
private volatile boolean configurationFrozen;
}
Spring源码-DefaultListableBeanFactory-源码解读
最新推荐文章于 2022-10-07 18:06:39 发布