S2JH經驗分享:控制jdbc:initialize-database與其餘bean加載順序

爲了便於乾淨的初始化部署運行S2JH框架,採用了jdbc:initialize-database來從SQL腳本中初始化框架基礎數據,其中遇到一個問題:git

框架使用了Spring與Quartz集成以JDBC方式進行Cluster集羣定時任務支持,其中一個須要提早準備的就是須要初始化好Quartz須要的相關數據表,可是按照默認設置Spring Scheduler始終會在jdbc:initialize-database以前就優先加載,致使spring scheduler加載過程拋出Quartz相關數據表Table Not Found的異常。 spring

因爲jdbc:initialize-database不是按照常規的bean id方式定義,致使無法直接以depends-on控制依賴加載順序,經過分析jdbc:initialize-database相關schema定義和對應源代碼,最終以一種特殊的depends-on寫法實現了順序控制:框架

<bean id="quartzClusterScheduler" class="lab.s2jh.schedule.ExtSchedulerFactoryBean" depends-on="org.springframework.jdbc.datasource.init.DataSourceInitializer#0">.net

詳見相關代碼:prototype

http://git.oschina.net/xautlx/s2jh/blob/master/prototype/src/main/resources/context/context-profiles.xmlxml

http://git.oschina.net/xautlx/s2jh/blob/master/prototype/src/main/resources/service/spring-schedule.xml部署

相關文章
相關標籤/搜索