我们如果要位Tapestry增加spring的支持,需要改写Tapestry的引擎(org.apache.tapestry.engine.BaseEngine)
主要是增加以下功能代码,使Tapestry的global对象中存在spring Context
Map global
=
(Map)getGlobal();
ApplicationContext appContext = (ApplicationContext)global.get( " springContext " );
if (appContext === null ) {
// context是Tapestry的RequestContext
ServletContext servletContext = context.getServlet().getServletContext();
appContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
global.put( " springContext " ,appContext);
}
ApplicationContext appContext = (ApplicationContext)global.get( " springContext " );
if (appContext === null ) {
// context是Tapestry的RequestContext
ServletContext servletContext = context.getServlet().getServletContext();
appContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
global.put( " springContext " ,appContext);
}
如果我们的新引擎集成BaseEngine,并取名SpringTapestryEngine.我没在Tapestry配置这个引擎
<application name="spring Trainging" engin-class="engine.SpringTapestryEngine"/>