spring源码分析—BeanFactory

BeanFactory
定义了IoC容器的基本功能规范

package org.springframework.beans.factory;

import org.springframework.beans.BeansException;
import org.springframework.core.ResolvableType;

public interface BeanFactory {

    //转义字符,用于获取BeanFactory本身
    String FACTORY_BEAN_PREFIX = "&";

    //根据名字获取bean
    Object getBean(String name) throws BeansException;

    //根据名字获取bean(带筛选,指定返回类型)
    <T> T getBean(String name, Class<T> requiredType) throws BeansException;

    //根据指定类型获取bean
    <T> T getBean(Class<T> requiredType) throws BeansException;

    //根据名字获取bean,带多个参数
    Object getBean(String name, Object... args) throws BeansException;

    //根据指定类型获取bean(带筛选,多个参数)
    <T> T getBean(Class<T> requiredType, Object... args) throws BeansException;

    //判断容器是否包含指定名字的bean
    boolean containsBean(String name);

    //判断指定名字的bean是否为单例的
    boolean isSingleton(String name) throws NoSuchBeanDefinitionException;

    //查询指定名字的bean是否是Prototype类型的
    boolean isPrototype(String name) throws NoSuchBeanDefinitionException;

    //判断指定名字的bean是否是特定类型的
    boolean isTypeMatch(String name, ResolvableType typeToMatch) throws NoSuchBeanDefinitionException;

    //判断指定名字的bean是否是特定类型的
    boolean isTypeMatch(String name, Class<?> typeToMatch) throws NoSuchBeanDefinitionException;

    //获得指定名字的bean的class类型
    Class<?> getType(String name) throws NoSuchBeanDefinitionException;

    //获取指定名字的bean的所有别名
    String[] getAliases(String name);

}

注意:getAliases,isPrototype,isSingleton方法都是对bean的属性进行判断或获取,bean的这些属性都是用户在BeanDefinition中定义的。

XmlBeanFactory
以XML格式定义了BeanDefinition,提供了最基本的IoC容器的功能。它本身未实现具体的IoC容器的功能,而是由它的继承体系实现的。它本身定义了XmlBeanDefinitionReader 对象通过Xml文件定义BeanDefinition。
继承体系
继承体系

package org.springframework.beans.factory.xml;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.core.io.Resource;

@Deprecated
@SuppressWarnings({"serial", "all"})
public class XmlBeanFactory extends DefaultListableBeanFactory {

    private final XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this);

    //构造器
    public XmlBeanFactory(Resource resource) throws BeansException {
        this(resource, null);
    }

    //构造器,加载Definitions
    public XmlBeanFactory(Resource resource, BeanFactory parentBeanFactory) throws BeansException {
        super(parentBeanFactory);
        this.reader.loadBeanDefinitions(resource);
    }
}

BeanDefinition

BeanDefinition的Resource定位

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值