spring配置hessian远程服务

1 篇文章 0 订阅
1 篇文章 0 订阅
使用eclipse创建hessian服务
对于Hessian而言,有服务端和客户端,所以我们的整合也需要分服务端的整合和客户端的整合。

hessian服务端源码结构



hessian 客户端源码结构



废话不多说,实现远程服务,最重要的是如何使用轮子,下面直接上配置文件,源代码:

http://download.csdn.net/download/heisemuyangquan/10272025

server配置
<? xml version = "1.0" encoding = "UTF-8" ?>
      xsi:schemaLocation = "http://www.springframework.org/schema/beans
      < bean class = "org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />
      < bean id = "userService" class = "com.hessian.service.impl.UserServiceImpl" />
      < bean name = "/userService"
           class = "org.springframework.remoting.caucho.HessianServiceExporter" >
            < property name = "service" ref = "userService" />
            < property name = "serviceInterface" value = "com.hessian.service.UserService" />
      </ bean >
</ beans >

client配置
<? xml version = "1.0" encoding = "UTF-8" ?>
      xsi:schemaLocation = "http://www.springframework.org/schema/beans
      < bean id = "userService"
           class = "org.springframework.remoting.caucho.HessianProxyFactoryBean" >
            < property name = "serviceUrl"
                 value = "http://localhost:8080/hessianServer/api/service/userService" />
            < property name = "serviceInterface" value = "com.hessian.service.UserService" />
      </ bean >
</ beans >


另外需要注意的是hessian和Spring的版本兼容问题

需要导入Spring的相关依赖要在pom中配置


pom.xml仅供参考,亲测可用

      < modelVersion > 4.0.0 </ modelVersion >
      < groupId > com.hiquanten </ groupId >
      < artifactId > hessianServer </ artifactId >
      < packaging > war </ packaging >
      < version > 0.0.1-SNAPSHOT </ version >
      < name > hessianServer Maven Webapp </ name >
      < url > http://maven.apache.org </ url >
      < properties >
            < spring.version > 4.3.7.RELEASE </ spring.version >
      </ properties >
      < dependencies >
            < dependency >
                 < groupId > com.caucho </ groupId >
                 < artifactId > hessian </ artifactId >
                 < version > 4.0.51 </ version >
            </ dependency >
            < dependency >
                 < groupId > junit </ groupId >
                 < artifactId > junit </ artifactId >
                 < version > 4.12 </ version >
                 < scope > test </ scope >
            </ dependency >
            < dependency >
                 < groupId > org.springframework </ groupId >
                 < artifactId > spring-core </ artifactId >
                 < version > ${spring.version} </ version >
            </ dependency >
            <!-- 2)这个jar 文件是所有应用都要用到的,它包含访问配置文件、创建和管理bean 以及进行Inversion of Control
                / Dependency Injection(IoC/DI)操作相关的所有类。如果应用只需基本的IoC/DI 支持,引入spring-core.jar
                及spring-beans.jar 文件就可以了。 -->
            < dependency >
                 < groupId > org.springframework </ groupId >
                 < artifactId > spring-beans </ artifactId >
                 < version > ${spring.version} </ version >
            </ dependency >
            <!-- 3)这个jar 文件为Spring 核心提供了大量扩展。可以找到使用Spring ApplicationContext特性时所需的全部类,JDNI
                所需的全部类,instrumentation组件以及校验Validation 方面的相关类。 -->
            < dependency >
                 < groupId > org.springframework </ groupId >
                 < artifactId > spring-context </ artifactId >
                 < version > ${spring.version} </ version >
            </ dependency >
            <!-- 4) 这个jar 文件包含对Spring 对JDBC 数据访问进行封装的所有类。 -->
            < dependency >
                 < groupId > org.springframework </ groupId >
                 < artifactId > spring- jdbc </ artifactId >
                 < version > ${spring.version} </ version >
            </ dependency >
            <!-- 5) 为JDBC、 Hibernate 、JDO、JPA等提供的一致的声明式和编程式事务管理。 -->
            < dependency >
                 < groupId > org.springframework </ groupId >
                 < artifactId > spring- tx </ artifactId >
                 < version > ${spring.version} </ version >
            </ dependency >
            <!-- 6)Spring web 包含Web应用开发时,用到Spring框架时所需的核心类,包括自动载入WebApplicationContext特性的类、Struts与JSF集成类、文件上传的支持类、Filter类和大量工具辅助类。 -->
            < dependency >
                 < groupId > org.springframework </ groupId >
                 < artifactId > spring-web </ artifactId >
                 < version > ${spring.version} </ version >
            </ dependency >
            <!-- 7)包含SpringMVC框架相关的所有类。 -->
            < dependency >
                 < groupId > org.springframework </ groupId >
                 < artifactId > spring- webmvc </ artifactId >
                 < version > ${spring.version} </ version >
            </ dependency >
            <!-- 8)Spring test 对JUNIT等测试框架的简单封装 -->
            < dependency >
                 < groupId > org.springframework </ groupId >
                 < artifactId > spring-test </ artifactId >
                 < version > ${spring.version} </ version >
                 < scope > test </ scope >
            </ dependency >
            < dependency >
                 < groupId > org.springframework </ groupId >
                 < artifactId > spring- aop </ artifactId >
                 < version > ${spring.version} </ version >
            </ dependency >
            <!-- Servlet web -->
            < dependency >
                 < groupId > javax.servlet </ groupId >
                 < artifactId > javax.servlet- api </ artifactId >
                 < version > 3.1.0 </ version >
            </ dependency >
      </ dependencies >
      < build >
            < finalName > hessianServer </ finalName >
            < plugins >
                 < plugin >
                      <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
                      < groupId > org.apache.maven.plugins </ groupId >
                      < artifactId > maven -compiler- plugin </ artifactId >
                      < version > 3.6.1 </ version >
                      < configuration >
                            < source > 1.8 </ source >
                            < target > 1.8 </ target >
                            < encoding > UTF8 </ encoding >
                      </ configuration >
                 </ plugin >
                 < plugin >
                      < groupId > org.mortbay.jetty </ groupId >
                      < artifactId > jetty - maven - plugin </ artifactId >
                      < version > 8.1.10.v20130312 </ version >
                      < configuration >
                            < webAppConfig >
                                 < contextPath > /HessianSpringMaven </ contextPath >
                            </ webAppConfig >
                      </ configuration >
                 </ plugin >
            </ plugins >
      </ build >
</ project >









































评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值