BeanDefinition作用

news2024/10/6 5:56:39

BeanDefinition接口

BeanDefinition 描述一个 Bean 实例,这个实例有哪些属性值、构造函数以及一些其他信息,就是描述Bean实例的信息。

BeanDefinition是一个接口,允许BeanFactoryPostProcessor 内省和修改属性值和其他 Bean 元数据。
点击了解BeanFactoryPostProcessor

意义

在这里插入图片描述
在spring流程中是现有BeanDefinition再有bean,bean是根据BeanDefinition中的信息去创建的,当然在还没创建bean的时候还可以修改BeanDefinition中的信息,这个就是BeanFactoryPostProcessor 接口的主要功能,如我们在xml中定义的${jdbc.name}最终替换为真正的值就是在实现BeanFactoryPostProcessor 接口完成的。

源码

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.
	 */
	@Nullable
	String 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()
	 */
	@Nullable
	String 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.
	 */
	@Nullable
	String 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.
	 * <p>Note that dependencies are normally expressed through bean properties or
	 * constructor arguments. This property should just be necessary for other kinds
	 * of dependencies like statics (*ugh*) or database preparation on startup.
	 */
	void setDependsOn(@Nullable String... dependsOn);

	/**
	 * Return the bean names that this bean depends on.
	 */
	@Nullable
	String[] 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.
	 * @see #setFallback
	 */
	void setPrimary(boolean primary);

	/**
	 * Return whether this bean is a primary autowire candidate.
	 */
	boolean isPrimary();

	/**
	 * Set whether this bean is a fallback autowire candidate.
	 * <p>If this value is {@code true} for all beans but one among multiple
	 * matching candidates, the remaining bean will be selected.
	 * @since 6.2
	 * @see #setPrimary
	 */
	void setFallback(boolean fallback);

	/**
	 * Return whether this bean is a fallback autowire candidate.
	 * @since 6.2
	 */
	boolean isFallback();

	/**
	 * Specify the factory bean to use, if any.
	 * This is the name of the bean to call the specified factory method on.
	 * <p>A factory bean name is only necessary for instance-based factory methods.
	 * For static factory methods, the method will be derived from the bean class.
	 * @see #setFactoryMethodName
	 * @see #setBeanClassName
	 */
	void setFactoryBeanName(@Nullable String factoryBeanName);

	/**
	 * Return the factory bean name, if any.
	 * <p>This will be {@code null} for static factory methods which will
	 * be derived from the bean class instead.
	 * @see #getFactoryMethodName()
	 * @see #getBeanClassName()
	 */
	@Nullable
	String 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.
	 * @see #getFactoryBeanName()
	 * @see #getBeanClassName()
	 */
	@Nullable
	String 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
	 * @see #getConstructorArgumentValues()
	 */
	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 defined for this bean.
	 * @since 5.0.2
	 * @see #getPropertyValues()
	 */
	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
	 */
	@Nullable
	String 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
	 */
	@Nullable
	String getDestroyMethodName();

	/**
	 * Set the role hint for this {@code BeanDefinition}. The role hint
	 * provides the frameworks as well as tools 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 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.
	 */
	@Nullable
	String 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
	 * itself but rather just serving as parent for concrete child bean definitions.
	 */
	boolean isAbstract();

	/**
	 * Return a description of the resource that this bean definition
	 * came from (for the purpose of showing context in case of errors).
	 */
	@Nullable
	String getResourceDescription();

	/**
	 * Return the originating BeanDefinition, or {@code null} if none.
	 * <p>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.
	 */
	@Nullable
	BeanDefinition getOriginatingBeanDefinition();

}

方法签名中文解释
void setParentName(@Nullable String parentName)设置该 bean 定义的父定义的名称(如果有)。
@Nullable String getParentName()返回该 bean 定义的父定义的名称(如果有)。
void setBeanClassName(@Nullable String beanClassName)指定该 bean 定义的 bean 类名称。
@Nullable String getBeanClassName()返回该 bean 定义的当前 bean 类名称。
void setScope(@Nullable String scope)重写该 bean 的目标范围,指定新的范围名称。
@Nullable String getScope()返回该 bean 当前目标范围的名称,或如果尚不清楚则返回 null。
void setLazyInit(boolean lazyInit)设置该 bean 是否应延迟初始化。
boolean isLazyInit()返回该 bean 是否应延迟初始化,即不在启动时急切实例化。仅适用于单例 bean。
void setDependsOn(@Nullable String… dependsOn)设置该 bean 依赖于初始化的 bean 的名称。
@Nullable String[] getDependsOn()返回该 bean 依赖的 bean 名称。
void setAutowireCandidate(boolean autowireCandidate)设置该 bean 是否是某些其他 bean 自动装配的候选者。
boolean isAutowireCandidate()返回该 bean 是否是某些其他 bean 自动装配的候选者。
void setPrimary(boolean primary)设置该 bean 是否是主要自动装配候选者。
boolean isPrimary()返回该 bean 是否是主要自动装配候选者。
void setFallback(boolean fallback)设置该 bean 是否是后备自动装配候选者。
boolean isFallback()返回该 bean 是否是后备自动装配候选者。
void setFactoryBeanName(@Nullable String factoryBeanName)指定要使用的工厂 bean(如果有)。这是调用指定工厂方法的 bean 的名称。
@Nullable String getFactoryBeanName()返回工厂 bean 名称(如果有)。
void setFactoryMethodName(@Nullable String factoryMethodName)指定工厂方法(如果有)。此方法将使用构造函数参数调用,或者如果没有指定参数则不带参数调用。
@Nullable String getFactoryMethodName()返回工厂方法(如果有)。
ConstructorArgumentValues getConstructorArgumentValues()返回该 bean 的构造函数参数值。返回的实例可以在 bean 工厂后处理期间进行修改。
boolean hasConstructorArgumentValues()返回是否定义了该 bean 的构造函数参数值。
MutablePropertyValues getPropertyValues()返回应用于该 bean 的新实例的属性值。返回的实例可以在 bean 工厂后处理期间进行修改。
boolean hasPropertyValues()返回是否为该 bean 定义了属性值。
void setInitMethodName(@Nullable String initMethodName)设置初始化方法的名称。
@Nullable String getInitMethodName()返回初始化方法的名称。
void setDestroyMethodName(@Nullable String destroyMethodName)设置销毁方法的名称。
@Nullable String getDestroyMethodName()返回销毁方法的名称。
void setRole(int role)设置该 BeanDefinition 的角色提示。
int getRole()获取该 BeanDefinition 的角色提示。
void setDescription(@Nullable String description)设置该 bean 定义的人类可读描述。
@Nullable String getDescription()返回该 bean 定义的人类可读描述。
ResolvableType getResolvableType()返回基于 bean 类或其他特定元数据的可解析类型。
boolean isSingleton()返回此 bean 是否为单例,所有调用都返回单个共享实例。
boolean isPrototype()返回此 bean 是否为原型,每次调用返回一个独立的实例。
boolean isAbstract()返回此 bean 是否为抽象,即不是用于实例化自身,而是作为具体子 bean 定义的父类。
@Nullable String getResourceDescription()返回该 bean 定义的资源描述(用于在出现错误时显示上下文)。
@Nullable BeanDefinition getOriginatingBeanDefinition()返回原始的 BeanDefinition,如果没有则返回 null。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1687249.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【simple-admin】simple-admin-core 首次服务启动 如何配置mysql数据库表 | 如何docker启动core

一、下载启动S-A 1、下载源码 https://github.com/suyuan32/simple-admin-core.git git clone https://github.com/suyuan32/simple-admin-core.git2、修改etc下yaml配置 需要对RPC和API 分别2个文件夹下的etc下的yaml进行修改 替换成我们的数据库 3、初始化数据库 核心代…

芯课堂 | UI Creator 物理键盘移植指南

LVGL提供输入设备的种类一共有5种&#xff0c;分别是&#xff1a;touchpad&#xff08;触摸板&#xff09;、mouse&#xff08;鼠标&#xff09;、keypad&#xff08;键盘&#xff09;、encoder&#xff08;编码器&#xff09;、button&#xff08;外部按键&#xff09;。而基于…

抖音直播预告|换新·升级 Aigtek安泰电子2024新产品发布会

多系列功放产品大升级&#xff01; 深耕电子测试仪器领域&#xff0c;攻坚行业尖端技术&#xff0c;不断自主研发与创新&#xff0c;是安泰电子一如既往的坚持&#xff01;通过长久技术积淀&#xff0c;Aigtek安泰电子多系列功放也在2024年迎来了全新升级&#xff01; 本次我们…

青年精英大会笔记

2024年5月16日上午 大会主席致辞【郑纬民】 郑纬民【清华大学教授、中国工程院院士】——78岁【看着精神抖擞】&#xff01;牛哇 学件初步探索【周志华】 南京大学 zhouzhnju.edu.cn Preliminary Exploration to Learnware 土生土长的 听完介绍感觉这个研究工作很不错&…

go语言中的一个特别的语法 //go:embed 可将将静态文件内容读取到string, []byte和 embed.FS 变量并直接打包到exe包中

go语言中的一个特别的语法 //go:embed 看上去像是注释&#xff0c;实则是golang中的一个内置的语法&#xff0c;而且是仅在你的go代码编译时生效的语法&#xff0c; 借助他我们可以将我们的静态资源文件读取到FS直接打包到我们的exe执行文件中。 同时他还支持文件的模式匹配…

揭秘未来,开启盲盒新篇章——打造你的专属盲盒小程序

一、引言 在这个充满未知与惊喜的时代&#xff0c;盲盒文化已经深入人心&#xff0c;成为年轻人追求新奇、体验刺激的新宠。如今&#xff0c;随着科技的快速发展&#xff0c;盲盒文化也迎来了全新的发展机遇。我们诚挚地邀请您一同踏上这场盲盒小程序开发的旅程&#xff0c;共…

通用代码生成器应用场景一,项目前期

通用代码生成器是一种自动化编程软件&#xff0c;是一种先进的编译系统。它具有表级抽象。把系统抽象为域对象&#xff0c;枚举&#xff0c;弹性登录模块&#xff0c;复杂版面和图形报表。使用通用代码生成器完成项目前期&#xff0c;比直接使用对应的高级语言快的多&#xff0…

秋招突击——算法打卡——5/24——两数之和

题目描述 实现代码 ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {int addNumber 0;// 表示进位ListNode* res ListNode();ListNode* curNode res;while(l1 && l2){curNode.value (l1.value l2.value addNumber) % 10 addNumber (l1.value l2.value…

当消费遇上AI:大模型如何成为行业“网红”?

在一个繁忙过后的周五晚上&#xff0c;美食发烧友Melissa和朋友痛快的享受了一顿海底捞火锅&#xff0c;餐毕&#xff0c;她像往常一样留下了服务评价&#xff0c;及时反馈是一位美食家的基本素养。 每天如同Melissa一样留下评价的客人不在少数&#xff0c;他们的真实体验反馈…

软件测试/测试开发丨学习笔记之Allure2测试报告

Allure2测试报告 1、使用 Allure2 运行方式-Python 1&#xff09;–alluredir 参数生成测试报告。 在测试执行期间收集结果 pytest [测试用例/模块/包] --alluredir./result/ (—alluredir这个选项 用于指定存储测试结果的路径)#生成在线的测试报告 allure serve ./result2…

EXPLAIN执行计划详解

EXPLAIN 是 MySQL 中的一个非常实用的命令&#xff0c;主要用于分析 SQL 查询语句的执行计划&#xff08;Query Execution Plan&#xff0c;QEP&#xff09;。通过这个命令&#xff0c;用户可以获取到数据库引擎如何执行特定的 SQL 语句的详细信息&#xff0c;这对于优化查询性…

我是如何使用 Next.js14 + Tailwindcss 重构个人项目的

前言 去年在学习 React 和 Nest 的时候&#xff0c;参考了大佬 imsyy 的项目 DailyHot&#xff0c;以此项目的灵感基于 React 开发&#xff0c;完成之后就没怎么在意。 后来发现这个项目还有点小流量&#xff0c;每天差不多 200-400 的 IP 访问量&#xff1a; 我又抽时间优…

使用Flask Swagger自动生成API文档

文章目录 安装Flask Swagger使用Flask Swagger生成API文档总结1. 自动化文档生成2. 交互式文档展示3. 规范化API设计4. 提升协作效率5. 支持多种格式 Flask Swagger是一种用于管理Flask API文档的工具。它基于OpenAPI规范&#xff0c;可以自动生成API的交互式文档。使用Flask S…

一键自动化博客发布工具,用过的人都说好(公众号篇)

之前收到很多朋友的要求&#xff0c;说是需要一个公众号的自动发布工具。 现在&#xff0c;它来了。 前提条件 前提条件当然是先下载 blog-auto-publishing-tools这个博客自动发布工具,地址如下&#xff1a;https://github.com/ddean2009/blog-auto-publishing-tools 公众号…

harbor 认证

Harbor 认证过程 Harbor以 Docker Registry v2认证为基础&#xff0c;添加上一层权限保护。1.v2 集成了一个安全认证的功能&#xff0c;将安全认证暴露给外部服务&#xff0c;让外部服务去实现2.强制用户每次Docker pull/push请求都要带一个合法的Token&#xff0c;Registry会…

Leecode560:和为 K 的子数组

这道题用暴力解法时间复杂度会很高&#xff0c;但是涉及到和等于多少的情况&#xff0c;一般情况下会考虑以空间换时间来存储前面获得的信息&#xff0c;然后将答案为某值的结果返回。 这里利用了累加然后通过哈希表寻找值的思想。就是先将前面的数全部加起来&#xff0c;统计…

可视化大屏的应用(26):地产/楼盘/楼宇

可视化大屏在地产、楼盘和楼宇上有以下几个价值&#xff1a; 数据展示和分析 可视化大屏可以将地产、楼盘和楼宇相关的数据以图表、地图等形式展示出来&#xff0c;帮助用户更直观地了解各种数据指标&#xff0c;如销售情况、租赁率、楼宇能耗等。通过数据的可视化展示和分析…

Lc43---- 1221. 分割平衡字符串(java版)---(贪心)(字符串)

1.题目描述 2.知识点和思路 &#xff08;1&#xff09;贪心算法的基本思想 选择性质&#xff1a;在每一步中&#xff0c;选择当前最优的选项&#xff0c;不考虑未来的后果。 局部最优解&#xff1a;通过一系列局部最优选择&#xff0c;构建全局最优解。 不可回溯&#xff1a;一…

Map六种遍历方式

下面是三组&#xff08;6种&#xff09;&#xff0c;Map 遍历方式的核心代码。 遍历方式有使用到增强for和迭代器。最下面有张图片&#xff0c;对做题有参考意义。 参考代码&#xff1a; Map map new HashMap();map.put("小猫","cat");map.put("小…

TypeScript-函数类型

函数类型 指给函数添加类型注解&#xff0c;本质上就是给函数的参数和返回值添加类型约束 function add(a: number,b: number) :number {return a b } let res: number res add(2 3) // 函数参数注解类型之后&#xff0c;不但限制了参数的类型还限制了参数为必填 优点&…