spring项目启动后立即执行方法的四种办法
一、定时任务
1.启动类头加 @EnableScheduling
3.类头加 @EnableScheduling
4.方法加 @Scheduled(cron = “0 0 7 ? * ** *”) //每天早上7点触发
二、controller 的 postman调用
三、方法上加注解@PostConstruct(推荐)
四、重写afterPropertiesSet方法
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/6452ba49d501d0b219db67b21851a828.jpeg)
程序启动执行顺序:
@PostConstruct > afterPropertiesSet() > initMethod()