Spring为各种远程訪问技术的集成提供了工具类。Spring远程支持是由普通(Spring)POJO实现的,这使得开发具有远程訪问功能的服务变得相当easy。

眼下,Spring支持四种远程技术:

  • 远程方法调用(RMI)

    通过使用 RmiProxyFactoryBean 和 RmiServiceExporter。Spring同一时候支持传统的RMI(使用java.rmi.Remote接口和java.rmi.RemoteException)和通过RMI调用器实现的透明远程调用(支持不论什么Java接口)。

  • Spring的HTTP调用器。Spring提供了一种特殊的同意通过HTTP进行Java串行化的远程调用策略。支持随意Java接口(就像RMI调用器)。相相应的支持类是 HttpInvokerProxyFactoryBean和 HttpInvokerServiceExporter。

  • Hessian

    通过 HessianProxyFactoryBean 和 HessianServiceExporter。能够使用Caucho提供的基于HTTP的轻量级二进制协议来透明地暴露服务。

  • Burlap。 Burlap是Caucho的另外一个子项目,能够作为Hessian基于XML的替代方案。Spring提供了诸如 BurlapProxyFactoryBean 和 BurlapServiceExporter 的支持类。
  • JAX RPC

    Spring通过JAX-RPC为远程Web服务提供支持。

  • JMS(待实现)
眼下就用到过了HttpInvoker,所以对配置进行总结下,为下一次开发奠定基础。

首先分为远程调用两部分。一个服务端。还有一个是client。
1、定义一个接口和接口的实现类,用于client发请求调用的
IRemoteService.java
public interface IRemoteService {
public void startRmote();
}

RemoteServiceImpl.java

public class RemoteServiceImpl implements IRemoteService {

	@Override
public void startRmote() {
// TODO Auto-generated method stub
System.out.println("this is remote --------------------------------");
} }

2、在web.xml下建立一个testRemote-servlet.xml文件。

配置暴露给client的接口实现类信息

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN/EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans> <bean name="remote" class="com.frame.rmote.RemoteServiceImpl" />
<bean name="/remoteservice"
class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
<property name="service" ref="remote" />
<property name="serviceInterface" value="com.frame.rmote.IRemoteService" />
</bean> </beans>

3、在服务端的web.xml配置上client要訪问的请求地址,
web.xml
       <servlet>
<servlet-name>testRemote</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>testRemote</servlet-name>
<url-pattern>/testRemoting/*</url-pattern>
</servlet-mapping>

服务端配置完成



client配置:

1、在client定义一个与服务端一样的接口
IRemoteService.java
public interface IRemoteService {
public void startRmote();
}

2、在applicationContext.xml中配置调用服务端的接口

	<bean id="iRemoteTest"
class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
<property name="serviceUrl" value="http://localhost:8080/Frame/testRemoting/remoteservice" />
<property name="serviceInterface" value="mf.newrise.test.IRemoteService" />
</bean>


測试:
public class TestRemote {

    public static void main(String[] args) {

       ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");

       IRemoteService service = (IRemoteService) applicationContext.getBean("iRemoteTest")

        service.startRemote();

    }

}

Spring中HttpInvoker远程方法调用总结的更多相关文章

  1. Java学习之路-Spring的HttpInvoker学习

    Hessian和Burlap都是基于HTTP的,他们都解决了RMI所头疼的防火墙渗透问题.但当传递过来的RPC消息中包含序列化对象时,RMI就完胜Hessian和Burlap了. 因为Hessian和 ...

  2. Velocity初探小结--Velocity在spring中的配置和使用

    最近正在做的项目前端使用了Velocity进行View层的数据渲染,之前没有接触过,草草过了一遍,就上手开始写,现在又回头细致的看了一遍,做个笔记. velocity是一种基于java的模板引擎技术, ...

  3. Spring中Bean的作用域、生命周期

                                   Bean的作用域.生命周期 Bean的作用域 Spring 3中为Bean定义了5中作用域,分别为singleton(单例).protot ...

  4. Spring中Bean的实例化

                                    Spring中Bean的实例化 在介绍Bean的三种实例化的方式之前,我们首先需要介绍一下什么是Bean,以及Bean的配置方式. 如果 ...

  5. 模拟实现Spring中的注解装配

    本文原创,地址为http://www.cnblogs.com/fengzheng/p/5037359.html 在Spring中,XML文件中的bean配置是实现Spring IOC的核心配置文件,在 ...

  6. Spring中常见的bean创建异常

    Spring中常见的bean创建异常 1. 概述     本次我们将讨论在spring中BeanFactory创建bean实例时经常遇到的异常 org.springframework.beans.fa ...

  7. Spring中配置数据源的4种形式

    不管采用何种持久化技术,都需要定义数据源.Spring中提供了4种不同形式的数据源配置方式: spring自带的数据源(DriverManagerDataSource),DBCP数据源,C3P0数据源 ...

  8. spring中InitializingBean接口使用理解

    InitializingBean接口为bean提供了初始化方法的方式,它只包括afterPropertiesSet方法,凡是继承该接口的类,在初始化bean的时候会执行该方法. 测试程序如下: imp ...

  9. Quartz 在 Spring 中如何动态配置时间--转

    原文地址:http://www.iteye.com/topic/399980 在项目中有一个需求,需要灵活配置调度任务时间,并能自由启动或停止调度. 有关调度的实现我就第一就想到了Quartz这个开源 ...

随机推荐

  1. Coursera-Algotithms学习

    Week1 Job Interview Question Social network connectivity. Given a social network containing N member ...

  2. setImmediate 函数详解

    1.兼容性 只有IE10以上的IE浏览器才支持. 2.用途 https://developer.mozilla.org/zh-CN/docs/Web/API/Window/setImmediate 该 ...

  3. 《The Story of My Life》Introductiom - Historical and Literary Context - Education of the Deaf and Blind

    At the time the Story of My Life was published, the idea of a disabled person as an active member of ...

  4. 准备你的Adempiere开发环境(2)- 安装

    1. 用pgAdmin III创建用户adempiere/adempiere:2. 创建adempiere360数据库:3. 导入<ADEMPIERE_HOME>\data\Adempie ...

  5. 【Spark】Spark的Standalone模式安装部署

    Spark执行模式 Spark 有非常多种模式,最简单就是单机本地模式,还有单机伪分布式模式,复杂的则执行在集群中,眼下能非常好的执行在 Yarn和 Mesos 中.当然 Spark 还有自带的 St ...

  6. 2013夏,iDempiere来了 - v1.0c Installers (Devina LTS Release) 2013-06-27

    怀揣着为中小企业量身定做一整套开源软件解决方案的梦想开始了一个网站的搭建.http://osssme.org/ iDempiere来了 - v1.0c Installers (Devina LTS R ...

  7. Sphinx-安装和配置

    本例是在Linux下, 环境 CentOS6.5 + PHP5.6.8 + MySQL5.6.13 + Sphinx2.3.1-beta 到官网下载对应环境的安装包, 按照官方文档指定步骤进行安装 第 ...

  8. CentOS搭建nginx与nginx-rtmp-module搭建流媒体服务器

    文章地址:http://blog.csdn.net/zph1234/article/details/52846223 本次搭建流媒体使用的环境是centos 7.0+nginx:让我们一起开始奇妙的流 ...

  9. 【vue】[Vue warn]: $attrs is readonly. 只读

    [Vue warn]: $attrs is readonly. 这个问题出现时,我自己都很懵逼,明明是在 data 内声明了一个 state  ,我在页面渲染完成后去改变它,但是一改变就报错,而且是我 ...

  10. docker运行环境安装-后续步骤(二)

    1.以非 root 用户身份管理 Docker [origalom@origalom ~]$ sudo groupadd docker # 创建docker用户组[origalom@origalom ...