在spring初始化過程中載入資料庫中的資料

2021-08-29 21:42:21 字數 502 閱讀 2109

spring 某些類 從 db 初始化 一些屬性

在spring初始化過程中載入資料庫中的資料

專案中有這個需求 需啟動時將某些屬性賦db讀到的值

達到同步資料的目的

考慮 1:建構函式 不可以 dao還未初始化 null point

2:xx 屬性 = dao.getxx.... dao還未初始化

使用beanpostprocessor可以

public class pbstrackmanagerpostprocessor implements beanpostprocessor

return obj;

}public object postprocessbeforeinitialization(object obj, string s)

throws bean***ception

}但要注意配置檔案

!!!!

default-lazy-init="false"

實時載入才可以

spring 解析初始化過程

1.xmlbeandefinitionreader 讀取解析檔案 解析encodedresource 編碼,校驗dtd,xsd,可以手動配置,沒有配置自動檢測,檢測方法有沒有doctype resolveentity 本地dtd 檔案頭 publicid systemid 忽略介面 beanname...

Spring容器初始化過程

1.preparerefresh 初始化placeholder source,校驗xml檔案 2.建立bean容器,載入並註冊bean。bean並沒有完成初始化,bean例項化未完成 初始化乙個defautllistablebeanfactory,載入beandefintion到beanfactor...

Spring初始化 啟動過程

為了讓web容器啟動時,也初始化spring,則需要在web.xml中配置 contextloaderlistener,web容器啟動時觸發 初始化spring org.springframework.web.context.contextloaderlistener 1.contextloader...