在服务器系统软件交付时,一般会通过定时来确定系统软件是否超出使用时间,这里提供一个较为简单的解决方案,待日后学成再进行补充
一、定时器
- 在Spring Boot项目启动类上添加@EnableScheduling注解,表示开启定时器
@EnableScheduling
@SpringBootApplication
public class Demo1Application {
public static void main(String[] args) {
SpringApplication.run(Demo1Application.class, args);
}
}
- 创建定时类
Cron表达式可以看:地址
@Component
public class PayJobs {
@Scheduled(cron = "0 0-55 14 * * ?")
public void queryPayStatus() throws Exception {
System.out.println("执行");
}
}
}
二、关闭服务器
暂时只会使用
public static ConfigurableApplicationContext context;
context=SpringApplication.run(Demo1Application.class, args);
//Demo1Application为context所在的类
Demo1Application.context.close();