hessian + spring 使用

前提
1.下载hessian包,spring-romote包
2.编写服务端接口,以及实现类(必须要有接口interface,接口调用来的)
2.配置服务端xml 提供servlet请求入扣
3.配置客户端 (此处建议 如果你的客户端比如pc,wap,手机客户端 端不属于你 请勿使用hessian)
4.将服务端要开放的接口以及方法以jar包形式给客户端

下面跟着我来一步一步实现hessian 相当简单
服务端

package com.wyh
//接口
interface ITest{
  public String holleHession(String params);
}
//实现类
class Test implements ITest
{
 Override
 public String holleHession(String params){
    system.out.println(params);
 }
}
//服务端 http://localhost:8080/test
web.xml

  <!-- heesian -->
  <servlet>
  <servlet-name>tourheesian</servlet-name>
  <servlet-class>com.caucho.hessian.server.HessianServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
  <init-param>
  <param-name>service-class</param-name>
  <param-value>com.wyh.Test</param-value>
  </init-param>
  </servlet>
  <servlet-mapping>
  <servlet-name>tourheesian</servlet-name>
  <url-pattern>/tourheesian</url-pattern>
  </servlet-mapping>


这里需要注意的是 客户端与服务端的hessian包必须是一致的 不然会出现expected integer at 0x53 java.lang.String....的错误


服务端 地址

请求服务端地址为  http://localhost:8080/test


客户端


import com.wyh.ITest

public clss testClient {

   public static void main (String [] args){

            HessianProxyFactory hessian = new HessianProxyFactory();
            ITest test = null;
            try {
                test = (ITest)hessian.create(ITest.class,"http://localhost:8080/test/tourheesian");
                system.out.println(test.holleHession("调用成功,就是这么简单"));
            } catch (Exception e) {
                
                e.printStackTrace();
            }
    }

}



spring 配置之后简化


    <bean id="test" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
        <property name="serviceUrl">
          <value>http://localhost:8080/51you_tour/tourheesian</value>
        </property>
        <property name="serviceInterface">
          <value>com.wyh.ITest</value>
        </property>
    </bean>


import com.wyh.ITest

public clss testClient {

   public static void main (String [] args){
            try {
              ITest  test = (ITest)BeanUtils.getBean("test");
                system.out.println(test.holleHession("调用成功,就是这么简单"));
            } catch (Exception e) {
                
                e.printStackTrace();
            }
    }

}


总结:

        刚接触对hessian认识还不是很深,在此就不做多评价。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值