spring InitializingBean和DisposableBean init-method 和destroy-method @PostConstruct @PreDestroy

对于初始化函数:

  1. @PostConstruct 注解的方法
  2. InitializingBean接口定义的回调afterPropertiesSet()
  3. Bean配置中自定义的初始化函数

对于析构则与上相同:

  1. @PreDestroy注解的方法
  2. DisposableBean接口定义的回调destroy()
  3. Bean配置中自定义析构函数
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd"
        default-init-method="init"
        default-destroy-method="close"
        >


    <bean id="user0" class="com.test.service.UserServiceIml" init-method="testInit" destroy-method="testBeforeDesstroy">

https://blog.csdn.net/windsunmoon/article/details/44276765

猜你喜欢

转载自www.cnblogs.com/antball/p/9993537.html