posts - 14, comments - 15, trackbacks - 0, articles - 0
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

spring集成hessian

Posted on 2009-05-20 18:12 析木 阅读(1867) 评论(0)  编辑  收藏 所属分类: WebService
1、在web.xml中的配置
<context-param>  
    
<param-name>contextConfigLocation</param-name>  
    
<param-value>  
        /WEB-INF/config/applicationContext.xml,   
        /WEB-INF/Hessian-servlet.xml   
    
</param-value>  
</context-param>  
           
<servlet>  
    
<servlet-name>Hessian</servlet-name>  
    
<servlet-class>  
        org.springframework.web.servlet.DispatcherServlet   
    
</servlet-class>  
    
<load-on-startup>1</load-on-startup>  
</servlet>  
           
<servlet-mapping>  
    
<servlet-name>Hessian</servlet-name>  
    
<url-pattern>/hessian/*</url-pattern>  
</servlet-mapping>
2.必须在WEB-INF目录下创建一个文件名格式为Hessian-servlet.xml的配置文件
<!-- 业务类 -->  
<bean id="hessianService" class="com.weijy.webservice.hessian.HessianServiceImpl"/>  
           
<!-- 远程服务 -->  
<bean name="/hessianService" class="org.springframework.remoting.caucho.HessianServiceExporter">  
    
<property name="service" ref="hessianService"/>  
    
<property name="serviceInterface">  
        
<value>com.cjm.webservice.hessian.HessianService</value>  
    
</property>  
</bean>
3.客户端调用
String url = "http://localhost:8888/spring2/hessian/hessianService";   
HessianProxyFactory factory 
= new HessianProxyFactory();   
HessianService hessianServer 
=    
            (HessianService)factory.create(HessianService.
class, url);   
String ret 
= hessianServer.sayHello("Raymond.chen");  
//.................... 
若使用spring则可通过 HessianProxyFactoryBean在客户端连接服务,在spring的配置中加入:
<bean id="hessianService " class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
   
<property name="serviceUrl" value="http://localhost:8888/spring2/hessian/hessianService"/>
   
<property name="serviceInterface" value="com.weijy.webservice.hessian.HessianService"/>
</bean>
加入以上的配置后,就可像使用其他的bean一样去操作了。原来实现一个webservice是可以这么简单的。

只有注册用户登录后才能发表评论。


网站导航:
 
我要啦免费统计