spring BeanDefinition详尽篇

BeanDefinition接口作为Spring中Bean定义的抽象,它包含了Bean的配置信息。RootBeanDefinition是最常见的实现,用于定义bean。ChildBeanDefinition表示父bean和子bean的关系,而GenericBeanDefinition综合了前两者的特点。本文将详细探讨BeanDefinition的实现和解析。
摘要由CSDN通过智能技术生成

定义

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;

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值