spring的BeanDefinition学习总结

1.BeanDefinition类结构图及属性图如下

                                                                                                    1.1 类关系图

                                                                                                    1.1 类及属性关系图

 

2.BeanMetadataElement接口有一个getSource方法获取类路径

public interface BeanMetadataElement {

   /**
    * Return the configuration source {@code Object} for this metadata element
    * (may be {@code null}).
    */
   @Nullable
   Object getSource();

}

3.AttributeAccessor接口是加bean额外信息的类,比如自己深度开发一些类属性都可以放在这里面

public interface AttributeAccessor {

   /**
    * Set the attribute defined by {@code name} to the supplied {@code value}.
    * If {@code value} is {@code null}, the attribute is {@link #removeAttribute removed}.
    * <p>In general, users should take care to prevent overlaps with other
    * metadata attributes by using fully-qualified names, perhaps using
    * class or package names as prefix.
    * @param name the unique attribute key
    * @param value the attribute value to be attached
    */
   void setAttribute(String name, @Nullable Object value);

   /**
    * Get the value of the attribute identified by {@code name}.
    * Return {@code null} if the attribute doesn't exist.
    * @param name the unique attribute key
    * @return the current value of the attribute, if any
    */
   @Nullable
   Object getAttribute(String name);

   /**
    * Remove the attribute identified by {@code name} and return its value.
    * Return {@code null} if no attribute under {@code name} is found.
    * @param name the unique attribute key
    * @return the last value of the attribute, if any
    */
   @Nullable
   Object removeAttribute(String name);

   /**
    * Return {@code true} if the attribute identified by {@code name} exists.
    * Otherwise return {@code false}.
    * @param name the unique attribute key
    */
   boolean hasAttribute(String name);

   /**
    * Return the names of all attributes.
    */
   String[] attributeNames();

}

4.AbstractBeanDefinition的一些属性

/**
 * Constant for the default scope name: {@code ""}, equivalent to singleton
 * status unless overridden from a parent bean definition (if applicable).
 */
public static final String SCOPE_DEFAULT = "";

/**
 * Constant that indicates no external autowiring at all.
 * @see #setAutowireMode
 *
 */
//自动注入模型类型  根据官网有四种 no byType byName constructor
public static final int AUTOWIRE_NO = AutowireCapableBeanFactory.AUTOWIRE_NO;

/**
 * Constant that indicates autowiring bean properties by name.
 * @see #setAutowireMode
 */
//自动注入byName
public static final int AUTOWIRE_BY_NAME = AutowireCapableBeanFactory.AUTOWIRE_BY_NAME;

/**
 * Constant that indicates autowiring bean properties by type.
 * @see #setAutowireMode
 */
//自动注入byType
public static final int AUTOWIRE_BY_TYPE = AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE;

/**
 * Constant that indicates autowiring a constructor.
 * @see #setAutowireMode
 */
//自动注入构造方法注入
public static final int AUTOWIRE_CONSTRUCTOR = AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR;

/**
 * Constant that indicates determining an appropriate autowire strategy
 * through introspection of the bean class.
 * @see #setAutowireMode
 * @deprecated as of Spring 3.0: If you are using mixed autowiring strategies,
 * use annotation-based autowiring for clearer demarcation of autowiring needs.
 */
@Deprecated
public static final int AUTOWIRE_AUTODETECT = AutowireCapableBeanFactory.AUTOWIRE_AUTODETECT;

/**
 * Constant that indicates no dependency check at all.
 * @see #setDependencyCheck
 */
public static final int DEPENDENCY_CHECK_NONE = 0;

/**
 * Constant that indicates dependency checking for object references.
 * @see #setDependencyCheck
 */
public static final int DEPENDENCY_CHECK_OBJECTS = 1;

/**
 * Constant that indicates dependency checking for "simple" properties.
 * @see #setDependencyCheck
 * @see org.springframework.beans.BeanUtils#isSimpleProperty
 */
public static final int DEPENDENCY_CHECK_SIMPLE = 2;

/**
 * Constant that indicates dependency checking for all properties
 * (object references as well as "simple" properties).
 * @see #setDependencyCheck
 */
public static final int DEPENDENCY_CHECK_ALL = 3;

/**
 * Constant that indicates the container should attempt to infer the
 * {@link #setDestroyMethodName destroy method name} for a bean as opposed to
 * explicit specification of a method name. The value {@value} is specifically
 * designed to include characters otherwise illegal in a method name, ensuring
 * no possibility of collisions with legitimately named methods having the same
 * name.
 * <p>Currently, the method names detected during destroy method inference
 * are "close" and "shutdown", if present on the specific bean class.
 */
public static final String INFER_METHOD = "(inferred)";

//类类型
@Nullable
private volatile Object beanClass;

@Nullable
private String scope = SCOPE_DEFAULT;

private boolean abstractFlag = false;

//懒加载默认为false
private boolean lazyInit = false;

//默认不支持自动注入
private int autowireMode = AUTOWIRE_NO;

private int dependencyCheck = DEPENDENCY_CHECK_NONE;

//是否依赖
@Nullable
private String[] dependsOn;

private boolean autowireCandidate = true;

private boolean primary = false;

private final Map<String, AutowireCandidateQualifier> qualifiers = new LinkedHashMap<>();

@Nullable
private Supplier<?> instanceSupplier;

private boolean nonPublicAccessAllowed = true;

private boolean lenientConstructorResolution = true;

@Nullable
private String factoryBeanName;

@Nullable
private String factoryMethodName;

@Nullable
private ConstructorArgumentValues constructorArgumentValues;

@Nullable
private MutablePropertyValues propertyValues;

private MethodOverrides methodOverrides = new MethodOverrides();

@Nullable
private String initMethodName;

@Nullable
private String destroyMethodName;

private boolean enforceInitMethod = true;

private boolean enforceDestroyMethod = true;

private boolean synthetic = false;

private int role = BeanDefinition.ROLE_APPLICATION;

@Nullable
private String description;

@Nullable
private Resource resource;

5.spring源码中在invokeBeanFactoryPostProcessors完成扫描和解析以及后置处理BeanFactoryPostProcesstor

6.ScannedGenericBeanDefinition  扫描的类用的这个BeanDefinition

7.AnnotatedGenericBeanDefinition 注册类使用的BeanDefinition

8.RootBeanDefinition必须有父类  ChildBeanDefinition必须有父类

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值