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