启动
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
@Component
public class SpringBootStartListener implements ApplicationListener {
@Override
public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
System.out.println("SpringBoot启动成功");
}
}
停止
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.stereotype.Component;
@Component
public class SpringBootStopListenner implements ApplicationListener {
// 监听kill pid 无法监听 kill -9 pid
@Override
public void onApplicationEvent(ContextClosedEvent contextClosedEvent) {
System.out.println("SpringBoot将要停止");
}
}