}
protected final String getModuleConfigPrefix(){
return this.moduleConfig.getPrefix();
}
protected final ActionServlet getActionServlet(){
return this.actionServlet;
}
public String getServletContextAttributeNameForBuffalo(){
return BUFFALO_CONTEXT_PREFIX;
}
public String getServletContextAttributeNameForSCP(){
return SERVLET_CONTEXT_PREFIX+getModuleConfigPrefix();
}
public void init(ActionServlet as, ModuleConfig mc)
throws ServletException {
// TODO Auto-generated method stub
log.info("BuffaloPlugIn init begin ......");
this.actionServlet = as;
this.moduleConfig = mc;
as.getServletContext().setAttribute (getServletContextAttributeNameForBuffalo(),getServletContextAttributeNameForSCP());
log.info("init end ");
}
}
把Buffalo中的SpringFactory和SpringUtil的获得WebApplicationContext的方式修改如下:
在SpringUtil中增加方法:
/**
* 获取WebApplicationContext
* @param context
* @return
*/
public static WebApplicationContext getWebApplicationContext(ServletContext context){
WebApplicationContext wac = null;
log.info("获取Wac begin......");
if(context == null){
log.info("context is null reutrn null");
return null;
}
String wacAttrName = (String)context.getAttribute(BuffaloPlugIn.BUFFALO_CONTEXT_PREFIX);
log.info("wacAttrName == "+wacAttrName);
if(wacAttrName != null){
wac = (WebApplicationContext)context.getAttribute(wacAttrName);
}
if(wac == null){
log.info("wac is null , obtain WebApplicationContext by WebApplicationContextUtils again");
wac = WebApplicationContextUtils.getWebApplicationContext (context);
}
return wac;
}
....//
WebApplicationContext appCtx = getWebApplicationContext (context);//WebApplicationContextUtils.getWebApplicationContext(context);
好了,修改完毕了。在Struts-config.xml中增加<plug-in className=.net.buffalo.service.spring.BuffaloPlugIn" />就OK了。Web.xml中只配置
<servlet>
<servlet-name>bfapp</servlet-name>
<servlet-class>net.buffalo.web.servlet.ApplicationServlet</servlet-class>
</servlet>
就完全支持SPring了。当然是建立在Spring+Struts构建了轻量级框架的基础上的。哈哈 不知道我自己能不能看懂。就此搁笔! 闪!!!!!给自己留的纪念。