Tapestry与Spring和hibernate的集成

Tapestry4.1与Spring的集成只能通过Hivemind,幸好在Hivemind中已经预留了这个接口,具体的步骤如下:
首先,实现两个类,这两个类是用于定位BeanFactory对象的。
MyWebApplicationContextUtils类:
package com.gwssi.bjais.kernal.spring;
import org.apache.tapestry.web.WebContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
/**
* @author root
*
*/
public class MyWebApplicationContextUtils extends WebApplicationContextUtils{
public static WebApplicationContext getWebApplicationContext(WebContext wc)
{
Object obj=wc.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
if(obj==null)
{
return null;
}
if(obj instanceof RuntimeException)
{
throw (RuntimeException)obj;
}
if(!(obj instanceof WebApplicationContext))
{
throw new IllegalStateException("Root context attribute is not of type WebApplicationContext:"+obj);
}
return (WebApplicationContext)obj;
}
public static WebApplicationContext getRequiredWebApplicationContext(WebContext wc)
{
WebApplicationContext wac=getWebApplicationContext(wc);
if(wac==null)
{
throw new IllegalStateException("No WebApplicationContext found:no ContextLoaderListener registered?");
}
return wac;
}
}
MySpringBeanFactoryHolderImpl类:
package com.gwssi.bjais.kernal.spring;
import org.apache.hivemind.events.RegistryShutdownListener;
import org.apache.hivemind.lib.impl.SpringBeanFactoryHolderImpl;
import org.apache.tapestry.web.WebContext;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ConfigurableApplicationContext;
/**
* @author root
*
*/
public class MySpringBeanFactoryHolderImpl extends SpringBeanFactoryHolderImpl implements RegistryShutdownListener{
private WebContext context;
public BeanFactory getBeanFactory()
{
if(super.getBeanFactory()==null)
{
super.setBeanFactory(MyWebApplicationContextUtils.getWebApplicationContext(this.getContext()));
}
return super.getBeanFactory();
}
public WebContext getContext()
{
return context;
}
public void setContext(WebContext context)
{
this.context=context;
}
public void registryDidShutdown()
{
((ConfigurableApplicationContext)super.getBeanFactory()).close();
}

}

第二步,在hivemind.xml配置文件中配置“hivemind.lib.DefaultSpringBeanFactoryHolder”的接口实现:
<module id="MyTapestry" version="1.0.0" package="com.gwssi.bjais.kernal.insideService">
<implementation service-id="hivemind.lib.DefaultSpringBeanFactoryHolder">
<invoke-factory>
<construct autowire-services="false" class="com.gwssi.bjais.kernal.spring.MySpringBeanFactoryHolderImpl">
<event-listener service-id="hivemind.ShutdownCoordinator"/>
<set-object property="context" value="service:tapestry.globals.WebContext"/>
</construct>
</invoke-factory>
</implementation>
</module>

第三步,在page规范文件中注入spring bean:
<inject property="loginService" object="spring:loginService"/>

Tapestry与hibernate的集成就通过Spring和hibernate的集成方式就行了。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值