1. 程式人生 > >spring InitializingBean和DisposableBean init-method 和destroy-method @PostConstruct @PreDestroy

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