关于在spring  容器初始化 bean 和销毁前所做的操作定义方式有三种

第一种注解:

  通过@PostConstruct 和 @PreDestroy 方法 实现初始化和销毁bean之前进行的操作

第二种是XML配置:

  通过 在xml中定义init-method 和  destory-method方法

第三种是接口实现:

  通过bean实现InitializingBean和 DisposableBean接口

具体接口和方法如表

Spring Bean 生命周期各阶段
相关接口及方法
Bean 自身方法
Bean 本身业务的方法:
配置文件中 init-method 和 destroy-method 指定的方法

Bean 生命周期接口方法
Initial izingBean 接口
DiposableBean 接口
BeanNameAware 接口
ApplicationCantextAware 接口
BeanFac町Aware 接口
其他

容器级生命周期接口方法
(一般称为“后处理器”)

lnstantiationAwareBeanPostPracessor 接口实现
BeanPostProcessor 接口实现

工厂级生命周期接口方法
(也可以归为容器级的)

AspecUWeavingEnabler
Con丑gurationC!assPostProcessor
CustomAutowireConfigurer 等

生命周期 时序图

Spring 的 init-method 和 destory-method的更多相关文章

  1. java代码中init method和destroy method的三种使用方式

    在java的实际开发过程中,我们可能常常需要使用到init method和destroy method,比如初始化一个对象(bean)后立即初始化(加载)一些数据,在销毁一个对象之前进行垃圾回收等等. ...

  2. Modified Least Square Method and Ransan Method to Fit Circle from Data

    In OpenCv, it only provide the function fitEllipse to fit Ellipse, but doesn't provide function to f ...

  3. 关于.ToList(): LINQ to Entities does not recognize the method ‘xxx’ method, and this method cannot be translated into a store expression.

    LINQ to Entities works by translating LINQ queries to SQL queries, then executing the resulting quer ...

  4. Invalid character found in method name. HTTP method names must be tokens

      o.apache.coyote.http11.Http11Processor : Error parsing HTTP request header Note: further occurrenc ...

  5. SpringBoot:Invalid character found in method name. HTTP method names must be tokens

    问题背景 关于SpringBoot应用挂了很久之后,会发生Invalid character found in method name. HTTP method names must be token ...

  6. Day04 -玩弄Ruby的方法:instance method与class method

    前情提要在第三天时,我们解说了如何在class里用include与extend,去使用module的method. Include is for adding methods to an instan ...

  7. tomcat 启动报错 Invalid character found in method name. HTTP method names must be tokens

    解决:Invalid character found in method name. HTTP method names must be tokens   阿里云上弄了一个tomcat,经常半夜发送崩 ...

  8. [Python] Python 之 function, unbound method 和 bound method

    首先看一下以下示例.(Python 2.7) #!/usr/bin/env python # -*- coding: utf-8 -*- class C(object): def foo(self): ...

  9. Python OOP(2)-static method,class method and instance method

    静态方法(Static Method): 一种简单函数,符合以下要求: 1.嵌套在类中. 2.没有self参数. 特点: 1.类调用.实例调用,静态方法都不会接受自动的self参数. 2.会记录所有实 ...

  10. Postman请求后台报错:Invalid character found in method name. HTTP method names must be tokens

    在使用Postman请求后台时Postman出现 开发工具控制台报 信息: Error parsing HTTP request header Note: further occurrences of ...

随机推荐

  1. 讲分布式唯一id,这篇文章很实在

    分布式唯一ID介绍 分布式系统全局唯一的 id 是所有系统都会遇到的场景,往往会被用在搜索,存储方面,用于作为唯一的标识或者排序,比如全局唯一的订单号,优惠券的券码等,如果出现两个相同的订单号,对于用 ...

  2. Intellij Idea显示回退和前进按钮的方法

    方法1:使用快捷键: 回到上一步  ctrl + alt + <-(左方向键) 回到下一步 ctrl + alt + ->(右方向键) 方法2:在界面显示: View -> 勾选To ...

  3. java注解@Transactional事务类内调用不生效问题及解决办法

    @Transactional 内部调用例子 在 Spring 的 AOP 代理下,只有目标方法由外部调用,目标方法才由 Spring 生成的代理对象来管理,这会造成自调用问题.若同一类中的其他没有@T ...

  4. AOP声明式事务

    1.spring-dao.xml修改 参考上面工程配置 <?xml version="1.0" encoding="UTF-8"?> <bea ...

  5. 测试平台系列(82) 解决APScheduler重复执行的问题

    大家好~我是米洛! 我正在从0到1打造一个开源的接口测试平台, 也在编写一套与之对应的完整教程,希望大家多多支持. 欢迎关注我的公众号测试开发坑货,获取最新文章教程! 回顾 上一节我们编写了在线执行R ...

  6. java的String参数格式化

    String类的format()方法用于创建格式化的字符串以及连接多个字符串对象.熟悉C语言的同学应该记得C语言的sprintf()方法,两者有类似之处.format()方法有两种重载形式. form ...

  7. uni-app开发 uni.scss 样式的整体化设置

    今天在写uni-app设计的时候,界面图片.图标规格一直无法正常显示.查看了uni-app官网的代码注释后,发现了在style中设置<style lang="scss"> ...

  8. 【Lua】实现代码执行覆盖率统计工具

    一.如何评估测试过程的测试情况? 很多时候完成功能测试后就会发布上线,甚至交叉和回归都没有足够的时间去执行,然后通过线上的补丁对遗漏的问题进行修复.如果可以在发布前了解本次测试过程所覆盖代码执行的比例 ...

  9. Ubuntu 18.04.5 LTS Ceph集群之 cephx 认证及使用普通用户挂载RBD和CephFS

    1.cephx认证和授权 1.1 CephX认证机制 Ceph使用cephx协议对客户端进行身份认证: 1.每个MON都可以对客户端进行身份验正并分发密钥, 不存在单点故障和性能瓶颈 2. MON会返 ...

  10. 洛谷 P6072 -『MdOI R1』Path(回滚莫队+01-trie)

    题面传送门 又是 ix35 神仙出的题,先以 mol 为敬 %%% 首先预处理出根节点到每个点路径上权值的异或和 \(dis_i\),那么两点 \(a,b\) 路径上权值的异或和显然为 \(dis_a ...