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

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方法