在生产系统中我们发布程序有时候会漏发spring的配置文件,我们又不想重新启动服务器因此可以用改方法进行刷新。
我们可以再管理页面中提供一个刷新context文件按钮进行刷新。
采用的方法为:
public final class WebUtil {
public static ConfigurableWebApplicationContext getConfigurableWebApplicationContext(ServletContext sc){
ConfigurableWebApplicationContext ctx = (ConfigurableWebApplicationContext)WebApplicationContextUtils
.getRequiredWebApplicationContext(sc);
return ctx;
}
}
ServletContext context = request.getSession().getServletContext();
ConfigurableWebApplicationContext cwc = WebUtil.getConfigurableWebApplicationContext(context);
cwc.refresh();