springboot优雅停机

springboot优雅停机_第1张图片

springboot优雅停机_第2张图片 

 

 
import org.springframework.context.annotation.Configuration;
 
import javax.annotation.PreDestroy;
 
@Configuration
public class DataBackupConfig {
 
    @PreDestroy
    public void backData(){
 
        System.out.println("开始备份..."+System.currentTimeMillis());
 
 
        System.out.println("结束备份..."+System.currentTimeMillis());
    }
 
}

 

package com.zkn.learnspringboot.destory;
 
import org.springframework.beans.factory.DisposableBean;
import org.springframework.boot.ExitCodeGenerator;
import org.springframework.stereotype.Component;
 
/**
 * Created by zkn on 2016/8/14.
 */
@Component
public class TestImplDisposableBean implements DisposableBean, ExitCodeGenerator {
 
    @Override
    public void destroy() throws Exception {
 
        System.out.println("<<<<<<<<<<<我被销毁了......................>>>>>>>>>>>>>>>");
        System.out.println("<<<<<<<<<<<我被销毁了......................>>>>>>>>>>>>>>>");
    }
 
    @Override
    public int getExitCode() {
 
        return 5;
    }
}

你可能感兴趣的:(springboot,spring,boot,java,spring)