首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

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

2012-01-10 
Struts2与Spring2配合使用如何获取ApplicationContext各位好,请问在Struts2中如何获取Spring2的Applicatio

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);
}

热点排行