码迷,mamicode.com
首页 > 编程语言 > 详细

springboot启动之后初始化数据的几种方法

时间:2019-10-18 18:59:41      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:and   cat   nbsp   context   refresh   list   eth   指定   stc   

1.实现ApplicationRunner和CommandLineRunner接口(建议)

当springboot的main方法快要执行结束时会调用afterRefresh然后再调用callRunners来加载所有的实现ApplicationRunner和CommandLineRunner的类然后执行run方法来初始化所写的东西

2.<1>实现InitializingBean接口(不建议) <2><bean>元素中配置指定的init-method  <3>@PostConstruct

3.实现ContextRefreshedEvent类型ApplicationListener接口ApplicationListener<ContextRefreshedEvent>,然后重写onApplicationEvent方法

springboot启动之后初始化数据的几种方法

标签:and   cat   nbsp   context   refresh   list   eth   指定   stc   

原文地址:https://www.cnblogs.com/olzoooo/p/11699781.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!