Spring学习笔记之初始化和销毁方法的调用次序

Multiple lifecycle mechanisms configured for the same bean, with different initialization methods, are called as follows:

Methods annotated with @PostConstruct
    afterPropertiesSet() as defined by the InitializingBean callback interface
    A custom configured init() method

Destroy methods are called in the same order:

Methods annotated with @PreDestroy
     destroy() as defined by the DisposableBean callback interface
     A custom configured destroy() method

http://andilyliao.iteye.com/blog/1062076

时间: 2024-07-28 22:33:07

Spring学习笔记之初始化和销毁方法的调用次序的相关文章

《深入Java虚拟机学习笔记》- 第19章 方法的调用与返回

<深入Java虚拟机学习笔记>- 第19章 方法的调用与返回

几种自定义Spring生命周期的初始化和销毁方法

Bean 的生命周期指的是 Bean 的创建.初始化.销毁的过程.Spring 提供了一些方法,可以让开发自定义实现在生命周期过程中执行一些额外操作. 1.在注解 @Bean 中指定初始化和销毁时执行的方法名. @Component public class Cat { public Cat() { System.out.println("new Cat()"); } void initMethod() { System.out.println("调用init初始化*****

Spring学习笔记--初始化和销毁Bean

可以使用bean的init-method和destroy-method属性来初始化和销毁bean.定义一个Hero类: package com.moonlit.myspring; public class Hero { public void born() { System.out.println("the hero is born."); } public void defaultBorn() { System.out.println("the hero is born b

Spring学习笔记--initmethod和构造函数、setter方法的加载顺序

今天学习了一下spring中bean的初始化和销毁,突然想了解一下初始化方法跟构造函数及setter方法注入的执行顺序,记录在此,仅作为学习笔记. 当实例化一个bean时,可能需要执行一些初始化操作来确保该bean处于可用状态.同样地,当不再需要bean时,将其从容器中移除是,我们可以还需要按顺序 执行一些清除工作. package com.zp.chapter2; public class Auditorium { private String name; public void doBefo

(002)spring容器中bean初始化、销毁时执行的方法及其3种实现方式

spring容器中bean初始化或者销毁时会执行一些方法,有3种实现方式. 1.实现InitializingBean.DisposableBean接口,在bean的属性设置后和bean销毁时分别执行afterPropertiesSet和destroy方法 pom.xml文件 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/

Spring学习笔记(一)

Spring学习笔记(一) Spring核心思想: IOC:  Inversion Of Control (控制反转) / DI: Dependency Injection (依赖注入) AOP: Aspect Oriented Programming (面向切面编程) IOC 1. 简单的应用 Model package com.wangj.spring.model; public class User { private String username; private String pas

不错的Spring学习笔记(转)

Spring学习笔记(1)----简单的实例 ---------------------------------   首先需要准备Spring包,可从官方网站上下载.   下载解压后,必须的两个包是spring.jar和commons-logging.jar.此外为了便于测试加入了JUnit包.   在Myeclipse中创建Java项目.   编写一个接口类,为了简单,只加入了一个方法.   Java代码   1.package com.szy.spring.interfacebean;  

Spring学习笔记 2014-7-9

Spring需要applicationContext.xml来管理各个Bean,其基本格式: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:t

spring学习笔记(一) Spring概述

博主Spring学习笔记整理大部分内容来自Spring实战(第四版)这本书.  强烈建议新手购入或者需要电子书的留言. 在学习Spring之前,我们要了解这么几个问题:什么是Spring?Spring的优势在哪里?怎么系统的学习Spring? 一.什么是Spring? Spring是一个开源的轻量级Java SE(Java 标准版本)/Java EE(Java 企业版本)开发应用框架,其目的是用于简化企业级应用程序开发. 那有人就会问了,Spring是如何简化开发的? 在传统开发中,一个应用是需