spring document

The container then injects those dependencies when it creates the bean.

Inversion of Control (IoC)

The BeanFactory interface provides an advanced configuration mechanism capable of managing any type of object. ApplicationContext is a sub-interface of BeanFactory. It adds easier integration with Spring's AOP features; message
resource handling (for use in internationalization), event publication; and application-layer specific contexts such as the WebApplicationContext for use in web applications.

IoC容器的高度抽象

Bean Overview

Within the container itself, these bean definitions are represented as BeanDefinition objects, which contain (among other information) the following metadata:
1、A package-qualified class name: typically the actual implementation class of the bean being defined.
2、Bean behavioral configuration elements, which state how the bean should behave in the container
(scope, lifecycle callbacks, and so forth).
3、References to other beans that are needed for the bean to do its work; these references are also called collaborators or dependencies.
4、Other configuration settings to set in the newly created object, for example, the number of connections to use in a bean that manages a connection pool, or the size limit of the pool.

用户能够在ApplicationContext容器外给其注册自己生成的对象,通过获取getBeanFactory()得到BeanFactory,这个BeanFacoty是DefaultListableBeanFactory的对象,DefaultListableBeanFactory有两个注册方法:registerSingleton(...)和registerBeanDefinition(...)

Ioc中bean别名的列子:

子系统A中通过一个名为“subsystemA-dataSource”配置了一个数据源关联,子系统B中通过一个名为"subsystemB-dataSource"配置了一个数据源关联;当组合他们到一个应用中,这个应用是通过一个名为“myApp-dataSource”配置数据源关联的;为了使得这三个不同配置用的是同一个数据源应该这样配置(这个配置放置在组合的引用中):

<alias name="subsystemA-dataSource" alias="subsystemB-dataSource"/>
<alias name="subsystemA-dataSource" alias="myApp-dataSource" />

循环依赖不能存在构造函数中,只能是set注入方式;循环依赖也就“鸡和蛋的科学问题”

转载于:https://my.oschina.net/u/782865/blog/264287

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值