3 .
@PreDestroy
destroy-method xml
DisposableBean,
faivorite - @PreDestroy.
:
application-context.xml :
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="shutDownBean" class="spring.ShutDownBean" />
<context:annotation-config/>
</beans>
@PreDestroy @PostDestroy.
, ShutDownBean, callback callback.
bean.
import javax.annotation.PreDestroy;
public final class ShutDownBean {
@PreDestroy
public static void shutDownMethod() {
System.out.println("Shutting down!");
}
}
.
, @PreDestroy :
AbstractApplicationContext applicationContext =
new ClassPathXmlApplicationContext("application-context.xml");
applicationContext.registerShutdownHook();
:
AbstractApplicationContext registerShutdownHook(), , .
, destroy-method , . , applcation-context.xml:
<bean id = "dataSource"
class = "org.apache.commons.dbcp.BasicDataSrouce"
destroy-method = "close">
destroy , .
, !