当前位置:网站首页>[Source code analysis] BeanFactory and FactoryBean
[Source code analysis] BeanFactory and FactoryBean
2022-07-31 16:39:00 【HUAWEI CLOUD】
前言: 作者简介:小明java问道之路,专注于研究计算机底层的博主,就职于金融公司后端高级工程师,擅长交易领域的高安全/可用/并发/性能的设计和架构
Java领域优质创作者、阿里云专家博主、华为云专家
如果此文还不错的话,还请关注、点赞、收藏三连支持一下博主哦
BeanFacotry
The root interface for accessing a Spring bean container.
This is the basic client view of a bean container; further interfaces such as {@link ListableBeanFactory} and {@link org.springframework.beans.factory.config.ConfigurableBeanFactory} are available for specific purposes.
This interface is implemented by objects that hold a number of bean definitions, each uniquely identified by a String name. Depending on the bean definition, the factory will return either an independent instance of a contained object (the Prototype design pattern), or a single shared instance (a superior alternative to the Singleton design pattern, in which the instance is a singleton in the scope of the factory). Which type of instance will be returned depends on the bean factory configuration: the API is the same. Since Spring 2.0, further scopes are available depending on the concrete application context (e.g. "request" and "session" scopes in a web environment).
用于访问SpringBean容器的根接口.
这是bean容器的基本客户端视图;其他接口,如{@link ListableBeanFactory}和{@link org.springframework.beans.factory.config.ConfigurableBeanFactory},可用于特定用途.
该接口由包含多个bean定义的对象实现,每个beanDefinitions are uniquely identified by a string name.根据bean定义,工厂将返回包含对象的独立实例(原型设计模式)或单个共享实例(An advanced alternative to the singleton design pattern,where instance is a singleton in factory scope).Which type of instance is returned dependsbean工厂配置:API是相同的.自Spring 2.0以来,根据具体的应用程序上下文(例如web环境中的“请求”和“会话”范围),More ranges can be used.
BeanFacotry是spring中比较原始的Factory.如XMLBeanFactory就是一种典型的BeanFactory.原始的BeanFactory无法支持spring的许多插件,如AOP功能、Web应用等.
ApplicationContext接口,它由BeanFactory接口派生而来,ApplicationContext包含BeanFactory的所有功能,通常建议比BeanFactory优先
FactoryBean
Interface to be implemented by objects used within a {@link BeanFactory} which are themselves factories for individual objects. If a bean implements this interface, it is used as a factory for an object to expose, not directly as a bean instance that will be exposed itself.
由{@link BeanFactory}The interface implemented by the object used within it,These objects are themselves factories for individual objects.如果一个bean实现了这个接口,It will be used as an object factory to expose,rather than directly as onebeaninstance to expose itself
一般情况下,Spring通过反射机制利用<bean>的class属性指定实现类实例化Bean,在某些情况下,实例化Bean过程比较复杂,如果按照传统的方式,则需要在<bean>中提供大量的配置信息.配置方式的灵活性是受限的,这时采用编码的方式可能会得到一个简单的方案.Spring为此提供了一个org.springframework.bean.factory.FactoryBean的工厂类接口,用户可以通过实现该接口定制实例化Bean的逻辑.FactoryBean接口对于Spring框架来说占用重要的地位,Spring自身就提供了70多个FactoryBean的实现.
边栏推荐
- jeecg master-slave database read-write separation configuration "recommended collection"
- 苹果官网样式调整 结账时产品图片“巨大化”
- 【愚公系列】2022年07月 Go教学课程 020-Go容器之数组
- adb shell error error: device unauthorized
- How to switch remote server in gerrit
- 字符指针赋值[通俗易懂]
- LevelSequence源码分析
- server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none 失败
- 【网络通信三】研华网关Modbus服务设置
- 【愚公系列】2022年07月 Go教学课程 022-Go容器之字典
猜你喜欢

Foreign media right, apple on May be true in inventory
![[pytorch] pytorch automatic derivation, Tensor and Autograd](/img/99/c9632a7d3f70a13e1e26b9aa67b8b9.png)
[pytorch] pytorch automatic derivation, Tensor and Autograd

【7.29】Code Source - 【Arrangement】【Stone Game II】【Cow and Snacks】【Minimum Number of Spawns】【Sequence】

利用PHP开发具有注册、登陆、文件上传、发布动态功能的网站

Three aspects of Ali: How to solve the problem of MQ message loss, duplication and backlog?

Qt practical cases (54) - using transparency QPixmap design pictures

t-sne 数据可视化网络中的部分参数+

外媒所言非虚,苹果降价或许是真的在清库存
![[TypeScript] In-depth study of TypeScript type operations](/img/d9/ee240ccba72e8d3114ee5c52ed0c8f.png)
[TypeScript] In-depth study of TypeScript type operations

LevelSequence源码分析
随机推荐
LeetCode_733_Image rendering
【愚公系列】2022年07月 Go教学课程 020-Go容器之数组
GP 6 overall architecture study notes
Flutter gets the height of the status bar statusbar
字符指针赋值[通俗易懂]
Intelligent bin (9) - vibration sensor (raspberries pie pico implementation)
动态规划之线性dp(下)
6-22 Vulnerability exploit - postgresql database password cracking
Foreign media right, apple on May be true in inventory
百度网盘网页版加速播放(有可用的网站吗)
MySQL多表联合查询
复杂高维医学数据挖掘与疾病风险分类研究
[pytorch] 1.7 pytorch and numpy, tensor and array conversion
基于Redis(SETNX)实现分布式锁,案例:解决高并发下的订单超卖,秒杀
全新宝马3系上市,安全、舒适一个不落
宁波大学NBU IT项目管理期末考试知识点整理
After the form is submitted, the page does not jump [easy to understand]
使用互相关进行音频对齐
2022年必读的12本机器学习书籍推荐
Premiere Pro 2022 for (pr 2022)v22.5.0


