spring動態載入(重新整理)配置檔案
阿新 • • 發佈:2019-02-17
在程式開發時,通常會經常修改spring的配置檔案,不得不重啟tomcat來載入spring配,費時費力。如果能在不重啟tomcat的情況下,手動動態載入spring
配置檔案,動態重啟讀取spring配置檔案,這樣會十分方便。spring貌似自帶refresh重新整理效果,只要獲取到XmlWebApplicationContext,呼叫refresh即可。
程式碼如下:
/** * 重新載入配置檔案(只有想不到沒有猜不到) */ @RequestMapping(value="refreshXmlWebApplicationContext2016}") public void refresh(HttpServletRequest request){ XmlWebApplicationContext context = (XmlWebApplicationContext)WebApplicationContextUtils .getWebApplicationContext(request.getServletContext()); context.refresh(); }