}
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構建了輕量級框架的基礎上的。
哈哈 不知道我自己能不能看懂。就此擱筆! 閃!!!!!
給自己留的紀念。
注: Spring2.0 Struts1.3 Hibernate3.0