BeanDefinition属性

系列文章目录



原文链接 https://zhhll.icu/2022/框架/spring/进阶/3.BeanDefinition属性/

BeanDefinition属性

public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccessor
      implements BeanDefinition, Cloneable {

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

   /**
    * Constant that indicates no autowiring at all.
    * @see #setAutowireMode
    */
   public static final int AUTOWIRE_NO = AutowireCapableBeanFactory.AUTOWIRE_NO;

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

   /**
    * Constant that indicates autowiring bean properties by type.
    * @see #setAutowireMode
    */
   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)";


   private volatile Object beanClass;
// bean的作用域,对应bean标签属性scope
   private String scope = SCOPE_DEFAULT;
// 是否抽象,对应bean标签属性abstract
   private boolean abstractFlag = false;
// 是否延迟加载,对应bean标签属性lazy-init
   private boolean lazyInit = false;
// 自动注入模式,对应bean标签属性autowire
   private int autowireMode = AUTOWIRE_NO;
// 依赖检查,spring3.0中弃用
   private int dependencyCheck = DEPENDENCY_CHECK_NONE;
// 一个bean的实例化依赖于另一个bean的实例化,对应bean标签属性depends-on
   private String[] dependsOn;
// 如果该属性设置为false,容器在进行自动装配对象时不会考虑该bean,但是该bean本身还是可以使用自动装配来注入其他bean的,对应bean标签属性autowire-candidate
   private boolean autowireCandidate = true;
// 自动装配时出现多个bean的候选时,如果primary设置为true,则作为首选,对应bean标签属性primary
   private boolean primary = false;
// 用于记录Qualifier,对应子元素qualifier
   private final Map<String, AutowireCandidateQualifier> qualifiers =
         new LinkedHashMap<String, AutowireCandidateQualifier>(0);
// 允许访问非公开的构造器和方法,通过程序设置,不在xml中配置
   private boolean nonPublicAccessAllowed = true;
// 是否以一种宽松的模式解析构造函数,如果为false,如果spring无法精确地定位某个构造函数的话则抛出异常
   private boolean lenientConstructorResolution = true;
// 记录工厂bean对应的id,对应bean标签属性factory-bean
   private String factoryBeanName;
// 记录工厂bean中生产bean的方法,对应bean标签属性factory-method
   private String factoryMethodName;
// 记录构造函数注入属性,对应bean标签属性contructor-arg
   private ConstructorArgumentValues constructorArgumentValues;
// 普通属性集合
   private MutablePropertyValues propertyValues;
// 方法重写的持有者,记录lookup-method、replaced-method元素
   private MethodOverrides methodOverrides = new MethodOverrides();
// 初始化方法,对应bean标签属性init-method
   private String initMethodName;
// 销毁方法,对应bean标签属性destory-method
   private String destroyMethodName;
// 是否执行init-method,通过程序设置,不在xml中配置
   private boolean enforceInitMethod = true;
// 是否执行destory-method,通过程序设置,不在xml中配置
   private boolean enforceDestroyMethod = true;
// 是否是用户定义的而不是应用程序本身定义的,创建AOP时为true,通过程序设置,不在xml中配置
   private boolean synthetic = false;
// 定义这个bean的角色,ROLE_APPLICATION:用户  ROLE_SUPPORT:某些复杂配置的一部分  ROLE_INFRASTRUCTURE:完全内部使用,与用户无关
   private int role = BeanDefinition.ROLE_APPLICATION;
// bean的描述信息
   private String description;
// bean定义的资源
   private Resource resource;

}
posted @   拾光师  阅读(4)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· DeepSeek在M芯片Mac上本地化部署
· 葡萄城 AI 搜索升级:DeepSeek 加持,客户体验更智能
点击右上角即可分享
微信分享提示