Spring Bean's life

In contrast, the lifecycle of a bean in a Spring container is more elaborate. It’s
important to understand the lifecycle of a Spring bean, because you may want to take
advantage of some of the opportunities that Spring offers to customize how a bean is
created. Figure 1.5 shows the startup lifecycle of a typical bean as it’s loaded into a
Spring application context.
As you can see, a bean factory performs several setup steps before a bean is ready to
use. Let’s break down figure 1.5 in more detail:
1 Spring instantiates the bean.
2 Spring injects values and bean references into the bean’s properties.
3 If the bean implements BeanNameAware, Spring passes the bean’s ID to the set-
BeanName() method.
4 If the bean implements BeanFactoryAware, Spring calls the setBeanFactory()
method, passing in the bean factory itself.
5 If the bean implements ApplicationContextAware, Spring calls the set-
ApplicationContext() method, passing in a reference to the enclosing application
context.
6 If the bean implements the BeanPostProcessor interface, Spring calls its post-
ProcessBeforeInitialization() method.
7 If the bean implements the InitializingBean interface, Spring calls its after-
PropertiesSet() method. Similarly, if the bean was declared with an initmethod,
then the specified initialization method is called.
8 If the bean implements BeanPostProcessor, Spring calls its postProcess-
AfterInitialization() method.
9 At this point, the bean is ready to be used by the application and remains in the
application context until the application context is destroyed.
10 If the bean implements the DisposableBean interface, Spring calls its
destroy() method. Likewise, if the bean was declared with a destroy-method,
the specified method is called.
Now you know how to create and load a Spring container. But an empty container
isn’t much good by itself; it doesn’t contain anything unless you put something in it.
To achieve the benefits of Spring DI, you must wire your application objects into the
Spring container. We’ll go into bean wiring in more detail in chapter 2.
参考文献
Spring in Action
Spring Bean's life的更多相关文章
- Spring8:一些常用的Spring Bean扩展接口
前言 Spring是一款非常强大的框架,可以说是几乎所有的企业级Java项目使用了Spring,而Bean又是Spring框架的核心. Spring框架运用了非常多的设计模式,从整体上看,它的设计严格 ...
- Spring Bean详细讲解
什么是Bean? Spring Bean是被实例的,组装的及被Spring 容器管理的Java对象. Spring 容器会自动完成@bean对象的实例化. 创建应用对象之间的协作关系的行为称为:装配( ...
- Spring Bean的生命周期(非常详细)
Spring作为当前Java最流行.最强大的轻量级框架,受到了程序员的热烈欢迎.准确的了解Spring Bean的生命周期是非常必要的.我们通常使用ApplicationContext作为Spring ...
- spring bean的生命周期
掌握好spring bean的生命周期,对spring的扩展大有帮助. spring bean的生命周期(推荐看) spring bean的生命周期
- spring bean的重新加载
架构体系 在谈spring bean的重新加载前,首先我们来看看spring ioc容器. spring ioc容器主要功能是完成对bean的创建.依赖注入和管理等功能,而这些功能的实现是有下面几个组 ...
- Spring Bean
一.Spring的几大模块:Data access & Integration.Transcation.Instrumentation.Core Spring Container.Testin ...
- 【转】Spring bean处理——回调函数
Spring bean处理——回调函数 Spring中定义了三个可以用来对Spring bean或生成bean的BeanFactory进行处理的接口,InitializingBean.BeanPost ...
- 在非spring组件中注入spring bean
1.在spring中配置如下<context:spring-configured/> <context:load-time-weaver aspectj-weaving=&q ...
- spring bean生命周期管理--转
Life Cycle Management of a Spring Bean 原文地址:http://javabeat.net/life-cycle-management-of-a-spring-be ...
- Spring Bean配置默认为单实例 pring Bean生命周期
Bean默认的是单例的. 如果不想单例需要如下配置:<bean id="user" class="..." scope="singleton&q ...
随机推荐
- 2.5配置的框架浅析「深入浅出ASP.NET Core系列」
希望给你3-5分钟的碎片化学习,可能是坐地铁.等公交,积少成多,水滴石穿,谢谢关注. 配置的使用流程 //第一步.初始化Builder var builder = new ConfigurationB ...
- Celery工具
什么是Celery Celery的功能 Celery是基于python实现的第三方组件,可以实现定时任务.周期任务等. Celery的组成 Celery的角色 - 任务,创建或发布任务. - 使用re ...
- 个人对【依赖倒置(DIP)】、【控制反转(IOC)】、【依赖注入(DI)】浅显理解
一.依赖倒置(Dependency Inversion Principle) 依赖倒置是面向对象设计领域的一种软件设计原则.(其他的设计原则还有:单一职责原则.开放封闭原则.里式替换原则.接口分离原则 ...
- web前端图片上传(3)--filereader
这篇文章主要是为了介绍一种文件上传的方式.当然文件中是包含图片的.如果大家仔细看我的第一篇web前端图片上传(1)就会知道,其实也是按照这种方式上传你的,但是由于上次时间比较紧张,没有详细的介绍今天的 ...
- php禁用函数设置及查看方法详解
这篇文章主要介绍了php禁用函数设置及查看方法,结合实例形式分析了php禁用函数的方法及使用php探针查看禁用函数信息的相关实现技巧,需要的朋友可以参考下 本文实例讲述了php禁用函数设置及查看方法. ...
- Webpack4教程 - 第三部分,如何使用插件
转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者.原文出处:https://wanago.io/2018/07/23/webpack-4-course-part ...
- git在本地向远程仓库创建分支
在本地的仓库种,如果想给upstream创建新分支并关联,需要执行 git push -u/--set-upstream 远程仓库名 远程分支名
- sqlsever存储过程配合代理作业自动定时建表
1.自动建表存储过程 USE [ThreeToOne] GO /****** Object: StoredProcedure [dbo].[WTO_CreateTable_ScanDoXXX] ...
- python函数与函数式编程
https://www.cnblogs.com/evablogs/p/6699515.html 在理解函数式编程之前,我还是对函数的调用,参数传递以及函数的嵌套调用一头雾水,还是花了点时间整理了写思绪 ...
- MySQL SET数据类型
SET: 多选字符串数据类型,适合存储“多个值”. 设定set的时候,同样需要设定“固定的几个值”:存储的时候,可以存储其中的若干个值. 设定set的格式: 字段名称 SET("选项1&q ...