版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_27868061/article/details/82934916
BeanDefinition是spring容器的核心数据接口,定义了bean的依赖关系以及初始化信息等
package org.springframework.beans.factory.config;
import org.springframework.beans.BeanMetadataElement;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.core.AttributeAccessor;
import org.springframework.lang.Nullable;
/*
* 一个BeanDefinition描述了一个bean实例,实例包含属性值,构造函数参数值,以及更多实现信息
* 这只是一个最小的接口:主要目的是允许就像PropertyPlaceholderConfigurer一样的BeanFactoryPostProcessor
* 修改属性值以及其他的bean元数据
*/
public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
/**
* 单例Scope的标识符
*/
String SCOPE_SINGLETON = ConfigurableBeanFactory.SCOPE_SINGLETON;
/**
* 原型Scope的标识符
*/
String SCOPE_PROTOTYPE = ConfigurableBeanFactory.SCOPE_PROTOTYPE;
/**
* 角色提示,表明BeanDefinition是应用程序的主要部分,通常对应于用户定义的Bean
*/
int ROLE_APPLICATION = 0;
/**
* 角色提示,表明BeanDefinition是一些较大配置的支持部分,通常是外部org.springframework.beans.factory.parsing.ComponentDefinition配置
*/
int ROLE_SUPPORT = 1;
/**
* 角色提示,表明BeanDefinition正在提供一个完全的北京角色,与最终用户无关
* 这个提示是在注册完全属于内部工作的bean时使用
*/
int ROLE_INFRASTRUCTURE = 2;
/**
* 设置父BeanDefinition名称
*/
void setParentName(@Nullable String parentName);
/**
* 获取副BeanDefinition名称
*/
@Nullable
String getParentName();
/**
* 指定BeanDefinition的类名称
* 在bean工厂后处理期间可以修改类名
*/
void setBeanClassName(@Nullable String beanClassName);
/**
* 返回BeanDefinition的类名
*/
@Nullable
String getBeanClassName();
/**
* 设置Bean的Scope标识符
*/
void setScope(@Nullable String scope);
/**
* 返回Bean的Scope标识符
*/
@Nullable
String getScope();
/**
* 设置是否应该懒惰的初始化
* 如果为false,这个bean将会在BeanFactory启动时执行单例的eager初始化时实例化
*/
void setLazyInit(boolean lazyInit);
/**
* 返回这个bean是否应该被懒惰的初始化
* 只应用于单例模式的Bean
*/
boolean isLazyInit();
/**
* 设置这个Bean初始化时以来的bean的名称
* bean工厂将保证首先初始化这些bean
*/
void setDependsOn(@Nullable String... dependsOn);
/**
* 返回依赖的bean名称
*/
@Nullable
String[] getDependsOn();
/**
* 设置这个bean是否可以自动连接(autowired)到其他bean
* 此标志仅用于影响基于类型的自动装配,不会影响名称的显式引用
*/
void setAutowireCandidate(boolean autowireCandidate);
/**
* 返回这个bean是否可以自动连接到其他bean
*/
boolean isAutowireCandidate();
/**
* Set whether this bean is a primary autowire candidate.
* <p>If this value is {@code true} for exactly one bean among multiple
* matching candidates, it will serve as a tie-breaker.
*/
void setPrimary(boolean primary);
/**
* Return whether this bean is a primary autowire candidate.
*/
boolean isPrimary();
/**
* 设置工厂bean的名称
*/
void setFactoryBeanName(@Nullable String factoryBeanName);
/**
* 获取工厂bean的名称
*/
@Nullable
String getFactoryBeanName();
/**
* 设置工厂方法,这个方法将会被调用.如果有传递构造函数参数
* 将在指定的工厂bean上调用该方法,或者作为本地bean类的静态方法
*/
void setFactoryMethodName(@Nullable String factoryMethodName);
/**
* 返回工厂方法名称
*/
@Nullable
String getFactoryMethodName();
/**
* 返回此bean的构造函数参数值
* 可以在bean工厂后处理期间修改返回的实例
*/
ConstructorArgumentValues getConstructorArgumentValues();
/**
* 是否有构造函数值定义
*/
default boolean hasConstructorArgumentValues() {
return !getConstructorArgumentValues().isEmpty();
}
/**
* 返回要应用于bean的新实例的属性值
*/
MutablePropertyValues getPropertyValues();
/**
* 是否有属性值定义
*/
default boolean hasPropertyValues() {
return !getPropertyValues().isEmpty();
}
/**
* 是否是单例模式
*/
boolean isSingleton();
/**
* 是否是原型模式
*/
boolean isPrototype();
/**
* bean是否是抽象的,抽象意味着不能实例化
*/
boolean isAbstract();
/**
* 获取此BeanDefinition的角色提示
*/
int getRole();
/**
* 可读描述
*/
@Nullable
String getDescription();
/**
* 资源描述
*/
@Nullable
String getResourceDescription();
/**
* 返回原始bean定义
* 此方法返回直接发起者,通过迭代originator chain查找用户定义的原始BeanDefinition
* Return the originating BeanDefinition, or {@code null} if none.
* Allows for retrieving the decorated bean definition, if any.
* <p>Note that this method returns the immediate originator. Iterate through the
* originator chain to find the original BeanDefinition as defined by the user.
*/
@Nullable
BeanDefinition getOriginatingBeanDefinition();
}
1.角色:bean的角色,目前不太清楚如何使用
2.scope:bean的模式,singleton,prototype等,决定了创建模式
3.parentName:父BeanDefinition名称
4.className:bean类名
5.lazyInit:是否懒惰初始化,只有单例bean有这个设置
6.dependsOn:依赖的bean,这些bean会首先实例化
7.autowireCandidate:别的bean中是否可以通过Autowired自动连接这个bean
8.primary:注入指定类型bean时,优先注入这个bean
9.factoryBeanName:工厂bean名称
10.factoryMethodName:工厂方法名
11.constructorArgimentValues:构造函数参数
12.PropertyValues:属性值