Hessian学习(3)——客户端使用spring

上一篇文章Hessian学习(2)——整合spring中服务端整合了spring,但是客户端没有,本文将总结一下客户端也加入spring的使用方法。


1.服务端代码不用变,仍然使用HessianServer2;

2.新建一个客户端项目,此处命名为HessianClient2_2;

3.导入相关jar包,此处为:

hessian-4.0.7.jar
junit-4.10.jar
spring-beans-3.1.1.RELEASE.jar
spring-context-3.1.1.RELEASE.jar
spring-context-support-3.1.1.RELEASE.jar
spring-core-3.1.1.RELEASE.jar

4.在src下新建一个spring管理文件,命名为:hessian-client.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
	http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
	http://www.springframework.org/schema/context 
	http://www.springframework.org/schema/context/spring-context-3.0.xsd">
	<!-- 客户端Hessian代理工厂Bean -->
    <bean id="myClient" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
    	<!-- 地址 -->
        <property name="serviceUrl">
            <value>http://localhost:28080/HessianServer2/hessian/hello</value>
        </property>
        <!-- 接口定义 -->
        <property name="serviceInterface">
            <value>包名.HelloService</value>
        </property>
    </bean>
</beans>


5.创建一个测试类:

public class SpringHessianTest {
	@Test
	public void testSpringHessian() {
		try {
			ApplicationContext context = new ClassPathXmlApplicationContext("hessian-client.xml");
			HelloService service = context.getBean(HelloService.class);
			System.out.println(service.helloWorld("spring client!"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
}
6.测试结果如下:



总结:无


代码路径:csdn code


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值