原文:Spring項目啟動后執行操作:ContextRefreshedEvent和ApplicationReadyEvent

一 Spring boot運行時,會發送以下事件 .ApplicationStartingEvent .ApplicationEnvironmentPreparedEvent:當Environment已經准備好,在context 創建前 .ApplicationContextInitializedEvent:在ApplicationContext 創建和ApplicationContextInit ...

2021-01-19 15:17 0 968 推薦指數:

查看詳情

Spring Boot啟動執行指定代碼

在開發時有時候需要在整個應用開始運行時執行一些特定代碼,比如初始化環境,准備測試數據等等。 在Spring中可以通過ApplicationListener來實現相關的功能,不過在配合Spring Boot使用時就稍微有些區別了。 創建ApplicationListener ...

Sat May 14 00:39:00 CST 2016 0 11126
spring項目啟動執行特定方法

1. 方法上加注解@PostConstruct@Compantpublic class InitDemo{ @PostConstruct public void init(){ //項目啟動就會執行這個方法 doSomething(); }}2.xml配置init-method<bean ...

Fri Jun 21 23:40:00 CST 2019 0 638
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM