定义
BeanDefinition接口继承了AttributeAccessor, BeanMetadataElement两个接口,其主要的作用是实现将Bean的定义转换为java对象,是对Bean定义的一个抽象,其中的各种属性对应了xml中的各种配置信息。
类依赖
Spring中最常用的就三个具体的实现类,分类是:RootBeanDefinition,ChildBeanDefinition,GenericBeanDefinition
RootBeanDefinition:最常用的类,用于标定bean的定义。
ChildBeanDefinition:与RootBeanDefinition必定一块出现,表示一个父bean下面有子bean,xml中配置如下:
<bean id="a" class="spring_study_aop.a" init-method="init" ></bean>
<bean id="b" class="spring_study_aop.b" init-method="init" parent="a"></bean>,目前的这种方式已经被GenericBeanDefinition替换了
GenericBeanDefinition: RootBeanDefinition+ ChildBeanDefinition= GenericBeanDefinition
代码以及解析
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;
/** * A BeanDefinition describes a bean instance, which has property values, * constructor argument values, and further information supplied by * concrete implementations. * * <p>This is just a minimal interface: The main intention is to allow a * {@link BeanFactoryPostProcessor} such as {@link PropertyPlaceholderConfigurer} * to introspect and modify property values and other bean metadata. * * @author Juergen Hoeller * @author Rob Harrop * @since 19.03.2004 * @see ConfigurableListableBeanFactory#getBeanDefinition * @see org.springframework.beans.factory.support.RootBeanDefinition * @see org.springframework.beans.factory.support.ChildBeanDefinition */ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
/** * 标记这个bean的作用域是单例 ,可以通过xml中scope属性来设置 */ String SCOPE_SINGLETON = ConfigurableBeanFactory.SCOPE_SINGLETON;
/** * 标记这个bean的作用域是单例 ,可以通过xml中scope属性来设置 */ String SCOPE_PROTOTYPE = ConfigurableBeanFactory.SCOPE_PROTOTYPE;
|