Spring中Bean的初始化与销毁(基于Spring4.x)

  1. 通过在bean中设置init-method和destroy-method

    配置bean

    spring-lifecycle.xml

    1
    2
    3
    4
    5
    6
    <?xml version="1.0" encoding="UTF-8"?>
    <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">
    <bean id="beanLifeCycle" class="com.sh.imcdemo.services.impl.BeanLifeCycle" init-method="start" destroy-method="stop"></bean>
    </beans>

    com.sh.imcdemo.services.impl 实现类

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×