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

来源:互联网 发布:上海老年人口 知乎 编辑:程序博客网 时间:2024/05/16 03:50

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


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

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

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

hessian-4.0.7.jarjunit-4.10.jarspring-beans-3.1.1.RELEASE.jarspring-context-3.1.1.RELEASE.jarspring-context-support-3.1.1.RELEASE.jarspring-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.xsdhttp://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 {@Testpublic 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
原创粉丝点击