spring项目启动后立即执行方法的四种办法

spring项目启动后立即执行方法的四种办法

一、定时任务
1.启动类头加 @EnableScheduling
3.类头加 @EnableScheduling
4.方法加 @Scheduled(cron = “0 0 7 ? * ** *”) //每天早上7点触发

二、controller 的 postman调用

三、重写afterPropertiesSet方法

四、方法上加注解@PostConstruct(推荐)

你可能感兴趣的:(spring项目启动后立即执行方法的四种办法)