如何拦截服务器上运行的端点的关闭事件(比如servlet的destroy方法,可以这么说)以进行日志记录或其他目的?
答案 0 :(得分:-1)
Spring 4 Java配置:
实施SmartLifecycle(使用基于Java的配置时,或将Java代码转换为XML):
@Configuration
public class CycleBean implements SmartLifecycle {
public CycleBean() {
}
@Override
public boolean isRunning() {
return true;
}
@Override
public void start() {
}
@Override
public void stop() {
//when stopped call
}
@Override
public int getPhase() {
return 0;
}
@Override
public boolean isAutoStartup() {
return true;
}
@Override
public void stop(Runnable arg0) {
//
}
}
参见http://docs.spring.io/spring/docs/3.1.x/spring-framework-reference/htmlsingle/spring-framework-reference.html第4.6段自定义bean的性质,如:
<bean id="lifecycleProcessor" class="org.springframework.context.support.DefaultLifecycleProcessor">
<!-- timeout value in milliseconds -->
<property name="timeoutPerShutdownPhase" value="10000"/>
</bean>