[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
<>前言
Spring在初始化过程中,将xml中定义的对象解析到了BeanDefinition对象中,我们有必要了解一下BeanDefinition的内部结构,有助于我们理解Spring的初始化流程。
<>一、BeanDefinition接口
下面我们翻译其注释。
A BeanDefinition describes a bean instance, which has property values,
constructor argument values, and further information supplied by concrete
implementations.
BeanDefinition描述一个bean实例,该实例具有属性值、构造函数参数值和由具体实现提供的进一步信息。
由这句注释可知,BeanDefinition里存着bean的属性值,构造函数等等的信息。由此猜测其实就是将xml里的bean属性,存到了BeanDefinition的某些属性里面,用的时候,从BeanDefinition的这些属性里取值。我们继续往下看。
This is just a minimal interface: The main intention is to allow a
BeanFactoryPostProcessor to introspect and modify property values and other
bean metadata.
这只是一个最小的接口:主要目的是允许BeanFactoryPostProcessor内省和修改属性值和其他bean元数据。
这句的
意思是我们可以通过BeanFactoryPostProcessor来修改加载到BeanDefinition对象中的bean的属性。这个如何操作,我们单独讲解,继续往下看。
下面就是BeanDefinition的方法和属性了,我们大概看一下都有哪些方法和属性。
由上图的方法可知,就是把xml中的标签属性,封装成了对象,这也体现了java面向对象的思想。BeanDefinition也有很多实现类,都是对BeanDefinition的扩展。我们在分析Spring源码中碰到了,再具体问题具体分析。
注意:开启注解扫描时,bean不会在xml中配置,spring通过component-scan标签扫描类时,也会把扫描到的类转化成BeanDefinition对象。这个我们在component-scan标签详细讲解。