以下内容是从书中摘录来的,但是我发现即使摘录一遍,对其内容的理解也会更加深入! Spring容器关闭过程 总结: 二、依赖注入
代码
|
对Spring的BeanFactory的学习小节
最新推荐文章于 2021-07-06 16:07:45 发布
以下内容是从书中摘录来的,但是我发现即使摘录一遍,对其内容的理解也会更加深入! Spring容器关闭过程 总结: 二、依赖注入
代码
|
2、constructor注入
三、自动装配
<bean id="foo" class="beanClass" autowire="autowire type"/>
有四种自动装配类型,byName,byType,constructor,autodetect,前两个是针对Set的自动装配,autodetect是由容器选择,在装配不成功(有重复情况)容器会抛异常而不是最先匹配原则。
<beans default-autowire="byName"/>缺省无自动装配,可设置缺省装配属性。
自动装配和非自动装配可混合使用。
四、BeanFactorPostProcessor
在BeanFactory载入所有Bean后,实例化Bean前,对BeanFactor做一些后处理工作,PropertyPlaceholderConfiger和CustomEditorConfigurer是SpringFrameWork自定义的BeanFactoryPostProcessor.
PropertyPlaceholderConfiger
CustomerEditorConfigurer
继承java.beans.PropertyEditorSupport实现自己的TypeEditor,实现其中的setAsText方法,代码事例
注册到SpringFrameWork
五、Event
系统事件ContextClosedEvent,ContextRefreshedEvent(初始化或者刷新时),RequestHandlerEvent Web请求被处理后。
接收事件的Bean 需实现ApplicationListener.
继承ApplicationEvent实现自己的Event,后由Bean调用context.publishEvent()发布事件,当然前提是你的Bean 要通过实现ApplicatonContextAware获得ApplicationContext.