bean的生命周期
2025-4-20
| 2025-4-20
Words 406Read Time 2 min
type
status
date
slug
summary
tags
category
icon
password
  1. 说明:bean对象创建是有jvm执行的,然后执行如下方法
  1. 执行构造器
  1. 执行set相关方法
  1. 调用bean的初始化方法(需要配置)
  1. 使用bean
  1. 当容器关闭时,调用bean的销毁方法(需要配置)

演示

实体类

beans.xml

测试

结果

notion image
可以看到和上面描述的一致,但是没有执行destroy方法,是因为destroy方法需要在容器销毁的时候执行,但现在并没有执行销毁方法程序就中断了。

执行销毁方法

结果

notion image
Centos-安装nextCloud私人云盘bean创建顺序
Loading...