Hessian探究(一)Hessian与springMVC结合

上一篇博客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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值