spring集成hessian

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是可以这么简单的。

你可能感兴趣的:(spring集成hessian)