当前位置: 代码迷 >> Java Web开发 >> Struts2与Spring2配合使用怎么获取ApplicationContext
  详细解决方案

Struts2与Spring2配合使用怎么获取ApplicationContext

热度:74   发布时间:2016-04-17 12:42:11.0
Struts2与Spring2配合使用如何获取ApplicationContext
各位好,
  请问在Struts2中如何获取Spring2的ApplicationContext对象,谢谢。

------解决方案--------------------
ActionContext ctx = ActionContext.getContext();
/**
* 取得spring的上下文环境
*
* @param session
* @return
*/
private WebApplicationContext getWebApplicationContext(ActionContext context) {
return WebApplicationContextUtils
.getWebApplicationContext(getServletContext(context));
}
------解决方案--------------------
漏掉一个方法
/**
* 取得ServletContext

* @param context
* @return
*/
private ServletContext getServletContext(ActionContext context) {
return (ServletContext) context.get(SERVLET_CONTEXT);
}
  相关解决方案