快速查看springboot项目的所有自启动执行方法

对于RestController可以访问地址,出发调用,但是自启动的类方法,在本地调试时,有时候会捣乱,输出大堆日志,修改数据等等

以下是总结的springboot项目的常见自启动方式

  • @Scheduled(fixedRate = 5 * 60 * 100)定时的cron时间特别短
  • @Scheduled(fixedRate = 30 * 60 * 1000)
  • 继承CommandLineRunner或ApplicationRunner的类的run方法
  • 被@EventListener注解的方法参数是ApplicationReadyEvent
  • @PostConstruct 类初始化后执行操作,但是不能保证spring容器已完全初始化,ApplicationContextAware不保证能取到值,最好用ApplicationRunner或者@EventListener
  • while(true) 空构造器里的持续执行

猜你喜欢

转载自blog.csdn.net/c5113620/article/details/91812556
今日推荐