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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM