Hessian探究(一)Hessian与springMVC结合

来源:互联网 发布:java解析json数组数据 编辑:程序博客网 时间:2024/06/08 14:27

上一篇博客Hessian探究(一)Hessian入门示例我们初步简单的介绍了一下Hessian的使用入门示例,我们是通过Servlet来暴露Hessian的对外服务的,接下来我们介绍一下通过SpringMVC的方式来暴露Hessian的对外调用服务

(1)在springMVC的配置文件springmvc-config.xml中进行配置,类似一个普通的Controller,这样我们就可以通过连接来访问Controller了,Hessian和springMVC结合也是类似这样。这样对外暴露的连接就是http://localhost/hessian.action了。

<bean id="helloService" class="com.tianjunwei.hessian.server.HelloServiceImpl" />      <!-- 使用Spring的HessianServie做代理 -->  <bean name="/hessian.action"      class="org.springframework.remoting.caucho.HessianServiceExporter">          <!-- service引用具体的实现实体Bean-->          <property name="service" ref="helloService" />          <property name="serviceInterface" value="com.tianjunwei.hessian.server.HelloService" />  </bean>
(2)客户端就可以访问Hessian使用springMVC暴露的服务。

package com.tianjunwei.hessian.client;import java.net.MalformedURLException;import com.caucho.hessian.client.HessianProxyFactory;import com.tianjunwei.hessian.server.HelloService;public class HelloServiceControllerMain {public static void main(String [] args) throws MalformedURLException{String url = "http://localhost/hessian.action";    System.out.println(url);    HessianProxyFactory factory = new HessianProxyFactory();    HelloService helloService = (HelloService) factory.create(HelloService.class, url);    System.out.println(helloService.helloWorld("world"));}}
运行结果:

hello,world



0 0
原创粉丝点击