在生产系统中我们发布程序有时候会漏发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();
本文介绍了一种在不重启服务器的情况下刷新Spring配置文件的方法。通过提供一个管理页面上的按钮来触发配置文件的刷新操作,使用`ConfigurableWebApplicationContext`接口的`refresh()`方法实现上下文的热更新。
1435

被折叠的 条评论
为什么被折叠?



