BeanDefinition 是 Spring Framework 中定义 Bean 的配置元信息接口.BeanDefinition描述一个bean. 包括bean的属性,构造函数参数列表,依赖bean,是否是单例,bean的类名等等

** 打印BeanDefinition (BeanDefinition 并非 Bean 终态,可以自定义修改)

Generic bean: class [com.rumenz.RumenzA]scope=abstract=falselazyInit=nullautowireMode=0dependencyCheck=0autowireCandidate=trueprimary=falsefactoryBeanName=nullfactoryMethodName=nullinitMethodName=nulldestroyMethodName=null

** BeanDefinition元信息

源码

/** Copyright 2002-2019 the original author or authors.** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at**      https://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/package org.springframework.beans.factory.config;import org.springframework.beans.BeanMetadataElement;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.core.AttributeAccessor;
import org.springframework.core.ResolvableType;
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} 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 {/*** Scope identifier for the standard singleton scope: {@value}.* <p>Note that extended bean factories might support further scopes.* @see #setScope* @see ConfigurableBeanFactory#SCOPE_SINGLETON*/String SCOPE_SINGLETON = ConfigurableBeanFactory.SCOPE_SINGLETON;/*** Scope identifier for the standard prototype scope: {@value}.* <p>Note that extended bean factories might support further scopes.* @see #setScope* @see ConfigurableBeanFactory#SCOPE_PROTOTYPE*/String SCOPE_PROTOTYPE = ConfigurableBeanFactory.SCOPE_PROTOTYPE;/*** Role hint indicating that a {@code BeanDefinition} is a major part* of the application. Typically corresponds to a user-defined bean.*/int ROLE_APPLICATION = 0;/*** Role hint indicating that a {@code BeanDefinition} is a supporting* part of some larger configuration, typically an outer* {@link org.springframework.beans.factory.parsing.ComponentDefinition}.* {@code SUPPORT} beans are considered important enough to be aware* of when looking more closely at a particular* {@link org.springframework.beans.factory.parsing.ComponentDefinition},* but not when looking at the overall configuration of an application.*/int ROLE_SUPPORT = 1;/*** Role hint indicating that a {@code BeanDefinition} is providing an* entirely background role and has no relevance to the end-user. This hint is* used when registering beans that are completely part of the internal workings* of a {@link org.springframework.beans.factory.parsing.ComponentDefinition}.*/int ROLE_INFRASTRUCTURE = 2;// Modifiable attributes/*** Set the name of the parent definition of this bean definition, if any.*/void setParentName(@Nullable String parentName);/*** Return the name of the parent definition of this bean definition, if any.*/@NullableString getParentName();/*** Specify the bean class name of this bean definition.* <p>The class name can be modified during bean factory post-processing,* typically replacing the original class name with a parsed variant of it.* @see #setParentName* @see #setFactoryBeanName* @see #setFactoryMethodName*/void setBeanClassName(@Nullable String beanClassName);/*** Return the current bean class name of this bean definition.* <p>Note that this does not have to be the actual class name used at runtime, in* case of a child definition overriding/inheriting the class name from its parent.* Also, this may just be the class that a factory method is called on, or it may* even be empty in case of a factory bean reference that a method is called on.* Hence, do <i>not</i> consider this to be the definitive bean type at runtime but* rather only use it for parsing purposes at the individual bean definition level.* @see #getParentName()* @see #getFactoryBeanName()* @see #getFactoryMethodName()*/@NullableString getBeanClassName();/*** Override the target scope of this bean, specifying a new scope name.* @see #SCOPE_SINGLETON* @see #SCOPE_PROTOTYPE*/void setScope(@Nullable String scope);/*** Return the name of the current target scope for this bean,* or {@code null} if not known yet.*/@NullableString getScope();/*** Set whether this bean should be lazily initialized.* <p>If {@code false}, the bean will get instantiated on startup by bean* factories that perform eager initialization of singletons.*/void setLazyInit(boolean lazyInit);/*** Return whether this bean should be lazily initialized, i.e. not* eagerly instantiated on startup. Only applicable to a singleton bean.*/boolean isLazyInit();/*** Set the names of the beans that this bean depends on being initialized.* The bean factory will guarantee that these beans get initialized first.*/void setDependsOn(@Nullable String... dependsOn);/*** Return the bean names that this bean depends on.*/@NullableString[] getDependsOn();/*** Set whether this bean is a candidate for getting autowired into some other bean.* <p>Note that this flag is designed to only affect type-based autowiring.* It does not affect explicit references by name, which will get resolved even* if the specified bean is not marked as an autowire candidate. As a consequence,* autowiring by name will nevertheless inject a bean if the name matches.*/void setAutowireCandidate(boolean autowireCandidate);/*** Return whether this bean is a candidate for getting autowired into some other bean.*/boolean isAutowireCandidate();/*** Set whether this bean is a primary autowire candidate.* <p>If this value is {@code true} for exactly one bean among multiple* matching candidates, it will serve as a tie-breaker.*/void setPrimary(boolean primary);/*** Return whether this bean is a primary autowire candidate.*/boolean isPrimary();/*** Specify the factory bean to use, if any.* This the name of the bean to call the specified factory method on.* @see #setFactoryMethodName*/void setFactoryBeanName(@Nullable String factoryBeanName);/*** Return the factory bean name, if any.*/@NullableString getFactoryBeanName();/*** Specify a factory method, if any. This method will be invoked with* constructor arguments, or with no arguments if none are specified.* The method will be invoked on the specified factory bean, if any,* or otherwise as a static method on the local bean class.* @see #setFactoryBeanName* @see #setBeanClassName*/void setFactoryMethodName(@Nullable String factoryMethodName);/*** Return a factory method, if any.*/@NullableString getFactoryMethodName();/*** Return the constructor argument values for this bean.* <p>The returned instance can be modified during bean factory post-processing.* @return the ConstructorArgumentValues object (never {@code null})*/ConstructorArgumentValues getConstructorArgumentValues();/*** Return if there are constructor argument values defined for this bean.* @since 5.0.2*/default boolean hasConstructorArgumentValues() {return !getConstructorArgumentValues().isEmpty();}/*** Return the property values to be applied to a new instance of the bean.* <p>The returned instance can be modified during bean factory post-processing.* @return the MutablePropertyValues object (never {@code null})*/MutablePropertyValues getPropertyValues();/*** Return if there are property values values defined for this bean.* @since 5.0.2*/default boolean hasPropertyValues() {return !getPropertyValues().isEmpty();}/*** Set the name of the initializer method.* @since 5.1*/void setInitMethodName(@Nullable String initMethodName);/*** Return the name of the initializer method.* @since 5.1*/@NullableString getInitMethodName();/*** Set the name of the destroy method.* @since 5.1*/void setDestroyMethodName(@Nullable String destroyMethodName);/*** Return the name of the destroy method.* @since 5.1*/@NullableString getDestroyMethodName();/*** Set the role hint for this {@code BeanDefinition}. The role hint* provides the frameworks as well as tools with an indication of* the role and importance of a particular {@code BeanDefinition}.* @since 5.1* @see #ROLE_APPLICATION* @see #ROLE_SUPPORT* @see #ROLE_INFRASTRUCTURE*/void setRole(int role);/*** Get the role hint for this {@code BeanDefinition}. The role hint* provides the frameworks as well as tools with an indication of* the role and importance of a particular {@code BeanDefinition}.* @see #ROLE_APPLICATION* @see #ROLE_SUPPORT* @see #ROLE_INFRASTRUCTURE*/int getRole();/*** Set a human-readable description of this bean definition.* @since 5.1*/void setDescription(@Nullable String description);/*** Return a human-readable description of this bean definition.*/@NullableString getDescription();// Read-only attributes/*** Return a resolvable type for this bean definition,* based on the bean class or other specific metadata.* <p>This is typically fully resolved on a runtime-merged bean definition* but not necessarily on a configuration-time definition instance.* @return the resolvable type (potentially {@link ResolvableType#NONE})* @since 5.2* @see ConfigurableBeanFactory#getMergedBeanDefinition*/ResolvableType getResolvableType();/*** Return whether this a <b>Singleton</b>, with a single, shared instance* returned on all calls.* @see #SCOPE_SINGLETON*/boolean isSingleton();/*** Return whether this a <b>Prototype</b>, with an independent instance* returned for each call.* @since 3.0* @see #SCOPE_PROTOTYPE*/boolean isPrototype();/*** Return whether this bean is "abstract", that is, not meant to be instantiated.*/boolean isAbstract();/*** Return a description of the resource that this bean definition* came from (for the purpose of showing context in case of errors).*/@NullableString getResourceDescription();/*** Return the originating BeanDefinition, or {@code null} if none.* Allows for retrieving the decorated bean definition, if any.* <p>Note that this method returns the immediate originator. Iterate through the* originator chain to find the original BeanDefinition as defined by the user.*/@NullableBeanDefinition getOriginatingBeanDefinition();}

方法解释

  • String: getBeanClassName: 返回当前 bean definition 定义的类名
  • ConstructorArgumentValues: getConstructorArgumentValues: 返回 bean 的构造函数参数
  • String[]: getDependsOn: 返回当前 bean 所依赖的其他 bean 的名称
  • String: getFactoryBeanName: 返回 factory bean 的名称
  • String: getFactoryMethodName: 返回工厂方法的名称
  • BeanDefinition: getOriginatingBeanDefinition: 返回原始的 BeanDefinition, 如果不存在返回null
  • String: getParentName: 返回当前 bean definition 的父 definition 的名字
  • MutablePropertyValues: getPropertyValues: 返回一个用于新的 bean 实例上的属性值
  • String: getScope: 返回当前 bean 的目标范围
  • boolean: isAbstract: 当前 bean 是否是 abstract, 意味着不能被实例化
  • boolean: isLazyInit: bean 是否是延迟初始化
  • boolean: isPrimary: bean 是否为自动装配的主要候选 bean
  • boolean: isPrototype: bean 是否是多实例
  • boolean: isSingleton: bean 是否是单例
  • void: setAutowiredCandidate(boolean): 设置 bean 是否对其他 bean 是自动装配的候选 bean
  • void: setBeanClassName(String): 指定 bean definition 的类名
  • void: setDependsOn(String ...): 设置当前 bean 初始化所依赖的 beans 的名称
  • void: setFactoryBeanName(String): 如果 factory bean 的名称
  • void: setFactoryMethodName(String): 设置工厂的方法名
  • void: setLazyInit(boolean lazyInit): 设置是否延迟初始化
  • void: setParentName(String): 设置父 definition 的名称
  • void: setPrimary(boolean): 设置是否主要的候选 bean
  • void: setScope(String): 设置 bean 的范围, 如: 单例, 多实例

https://rumenz.com/rumenbiji/spring-beandefinition.html

Spring中的BeanDefinition相关推荐

  1. spring中默认标签Bean标签解析一

    在Spring种有两种标签,一种是默认标签,另一种是自定义标签.对两种标签的用法和解析方式存在着很大的不同. 首先分析的是默认标签的解析过程. 解析标签的入口代码 protected void par ...

  2. spring中IoC和AOP的实现

    6.2 spring IoC IoC容器是Spring的核心.容器从配置文件中读取需要创建哪些对象,并在创建后按照要求把它们进行装配,通过这样的方法达到业务代码解耦的目的.不仅如此,spring还负责 ...

  3. 惊呆了,Spring中竟然有12种定义bean的方法

    前言 在庞大的 Java 技术体系中,Spring 有着举足轻重的地位,它给每位开发者带来了极大的便利和惊喜. 我们都知道 Spring 是创建和管理bean的工厂,它提供了多种方式定义 bean,能 ...

  4. 9种设计模式在Spring中的运用,一定要非常熟练!

    点击上方"方志朋",选择"设为星标" 回复"666"获取新整理的面试文章 作者:iCoding91 https://blog.csdn.ne ...

  5. spring中那些让你爱不释手的代码技巧

    紧接上文<spring中这些能升华代码的技巧,可能会让你爱不释手>.本文继续总结我认为spring中还不错的知识点,希望对您有所帮助. 一. @Conditional的强大之处 不知道你们 ...

  6. 【Spring源码】Spring中的AOP底层原理分析

    AOP中的几个概念 Advisor 和 Advice Advice,我们通常都会把他翻译为通知,其实很不好理解,其实他还有另外一个意思,就是"建议",我觉得把Advice理解为&q ...

  7. Spring中的@ Component,@ Repository和@Service批注有什么区别?

    @Repository @Component , @Repository和@Service批注可以在Spring中互换使用吗,或者除了充当注解设备外,它们还提供任何特定功能吗? 换句话说,如果我有一个 ...

  8. Spring中property-placeholder的使用与解析

    Spring中property-placeholder的使用与解析 我们在基于spring开发应用的时候,一般都会将数据库的配置放置在properties文件中. 代码分析的时候,涉及的知识点概要: ...

  9. 动态代理以及对应Spring中AOP源码分析

    AOP(面向切面编程)在Spring中是被广泛应用的(例如日志,事务,权限等),而它的基本原理便是动态代理. 我们知道动态代理有两种:基于JDK的动态代理以及基于CGlib动态代理.以下是两种动态代理 ...

最新文章

  1. fot mac matlab_matlab for mac的 安装-亲手实验
  2. Kafka消息序列化和反序列化(上)
  3. Dependency 'mysql:mysql-connector-java:5.1.28' not found【解决方案】
  4. HashMap如何在Java中工作
  5. java版本streamgobbler_java调用本地命令 Runtime class's exec() method
  6. 双linux共用swap,在Linux和FreeBSD系统上共享swap空间
  7. 对语言模型(Language Model)与n-gram的理解
  8. java 读取读取配置文件
  9. 细说php精要版 百度云,细说php精要版
  10. S7-200SMART与昆仑通态触摸屏以太网通信的具体方法和步骤(图文)
  11. java仓库管理设计报告_基于javaweb的仓库管理系统的设计和实现 毕业论文
  12. 《编译原理(英文版.第2版)》
  13. php内存设置,修改php运行内存大小的限制
  14. linux 中的rime 输入法 自定义 新世纪五笔输入法
  15. CuteFTP 问题及 ftp 模式详解
  16. 【8022】产品管理与产品营销的区别
  17. WebSocket的JavaScript例子
  18. 将Discuz!设置到新版应用中心,无需升级Discuz!版本的方法(临时方案)
  19. 2021 Java面试题总结,附答案(个人遇到面试题汇总)
  20. 计算机资源管理菜单包括哪些,玩转Win7之“资源管理器窗口” -电脑资料

热门文章

  1. 用 HTML 格式导出 Excel 时,如何保留显示网格线
  2. 蓝桥杯 ADV-92 算法提高 求最大公约数
  3. 1004. 成绩排名 (20)-PAT乙级真题
  4. 常见的几种 RuntimeException
  5. list集合去除重复对象
  6. shell脚本报错问题: -bash: ./test.sh: /bin/sh^M: bad interpreter: No such file or directory
  7. HDU-3466-Proud Merchants
  8. Python Day10 MySQL 01
  9. 深入浅出OOP(一): 多态和继承(早期绑定/编译时多态)
  10. 何以笙箫默,一部有剧情的创意广告集?