tapestry4+spring2+xfire+hibernate3+proxool 开发过程问题一

tapestry 和 spring 的合并,修改hivemodule.xml如下:
xml 代码
 
  1.    
  2.     <contribution configuration-id="tapestry.url.ServiceEncoders">  
  3.         <direct-service-encoder id="direct" stateless-extension="direct" stateful-extension="sdirect"/>  
  4.         <page-service-encoder id="page" extension="html" service="page"/>  
  5.         <page-service-encoder id="external" extension="external" service="external"/>  
  6.         <asset-encoder id="asset" path="/assets"/>  
  7.         <extension-encoder id="ext" extension="svc" after="*"/>  
  8.     contribution>  
  9.   
  10.       
  11.     <service-point id="SpringApplicationInitializer"  
  12.         interface="org.apache.tapestry.services.ApplicationInitializer"  
  13.         visibility="private">  
  14.         <invoke-factory>  
  15.             <construct class="com.javaforge.tapestry.spring.SpringApplicationInitializer">  
  16.                 <set-object property="beanFactoryHolder"  
  17.                     value="service:hivemind.lib.DefaultSpringBeanFactoryHolder" />  
  18.             construct>  
  19.         invoke-factory>  
  20.     service-point>  
  21.   
  22.       
  23.     <contribution configuration-id="tapestry.init.ApplicationInitializers">  
  24.         <command id="spring-context" object="service:SpringApplicationInitializer" />  
  25.     contribution>  

即可通过下面方式进行调用。
java 代码
 
  1. @InjectObject("spring:pointsDao")    
  2. public abstract IPointsDao getPointsDao();    


还有一种方法:

java 代码
 
  1. import javax.servlet.ServletContext;  
  2. import org.apache.commons.logging.Log;  
  3. import org.apache.commons.logging.LogFactory;  
  4. import org.springframework.context.ApplicationContext;  
  5. import org.springframework.web.context.support.WebApplicationContextUtils;  
  6.   
  7. public class ServiceLocator {  
  8.        private Log logger = LogFactory.getLog(this.getClass());  
  9.        private ServletContext context = null;  
  10.        private ApplicationContext appContext;  
  11.        private static ServiceLocator instance = null;  
  12.   
  13.        public ServiceLocator(ServletContext servletContext) {  
  14.               context = servletContext;  
  15.               appContext = WebApplicationContextUtils.getRequiredWebApplicationContext(getContext());  
  16.               logger.info("Spring Service locator bean initialize ...");  
  17.        }  
  18.   
  19.        public Object lookupService(String serviceBeanName) {  
  20.               return appContext.getBean(serviceBeanName);  
  21.        }  
  22.   
  23.        public static synchronized ServiceLocator getInstance(ServletContext servletContext) {  
  24.               if (instance == null)  
  25.                   instance = new ServiceLocator(servletContext);  
  26.               return instance;  
  27.        }  
  28.   
  29.        public static synchronized ServiceLocator getInstance() {  
  30.               return instance;  
  31.        }  
  32.   
  33.        public ServletContext getContext() {  
  34.               return context;  
  35.        }  
  36. }
java 代码
 
  1. import javax.servlet.ServletException;  
  2. import org.springframework.web.context.ContextLoaderServlet;  
  3.   
  4. public class ContextLoaderServletImpl extends ContextLoaderServlet {  
  5.   
  6.     private static final long serialVersionUID = 1L;  
  7.   
  8.     public void init() throws ServletException {  
  9.         super.init();  
  10.         ServiceLocator.getInstance(getServletContext());  
  11.     }  
  12. }   

在web.xml中添加如下代码
xml 代码
 
  1. <!-- Spring Config -->  
  2. <context-param>  
  3.     <param-name>contextConfigLocation</param-name>  
  4.     <param-value>/WEB-INF/applicationContext-*.xml</param-value>  
  5. </context-param>  
  6. <servlet>  
  7.     <servlet-name>SpringContextServlet</servlet-name>  
  8.     <servlet-class>cn.com.polchina.auction.tapestry.ContextLoaderServletImpl</servlet-class>  
  9.     <load-on-startup>2</load-on-startup>  
  10. </servlet>  

如下调用即可:

java 代码
 
  1. ITest it = (ITest) ServiceLocator.getInstance().lookupService("testBean");  



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值