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. 1年内4次架构调整,谈Nice的服务端架构变迁之路

    Nice 本身是一款照片分享社区类型的应用,在分享照片和生活态度的同时可以在照片上贴上如品牌.地点.兴趣等tag. Nice从2013.10月份上线App Store到目前每天2亿PV,服务端架构经过 ...

  2. Fedora 28 设置yum代理

    编辑  vi /etc/dnf/dnf.conf 文件 添加一行代理设置:proxy=http://****:****

  3. mysql,给每一条数据的某一个字段生成不同的随机数

    UPDATE t_article ta-- 利用LEFT JOIN的方式进行关联修改 LEFT JOIN(-- 先通过查询的方式给每一条数据生成对应的10-500之间随机数 SELECT articl ...

  4. STL源码剖析(set/map)

    SGI STL中set/map底层都是通过RB-tree实现的. 首先看看RB-tree结点的定义 typedef bool __rb_tree_color_type; const __rb_tree ...

  5. 转:C#操作摄像头

    转自: http://blog.csdn.NET/chenhongwu666/article/details/40594365 如有雷同,不胜荣幸,若转载,请注明 最近做项目需要操作摄像头,在网上百度 ...

  6. post请求方式的翻页爬取内容及思考

    1 #coding=utf-8 import urllib2 import urllib import json output = open('huizho.json', 'w') for page ...

  7. php学记笔记之函数用途

    echo '<pre>';//格式化输出字符 isset();//判断变量是否存在 array_key_exists('key',$arr);//判断数组下标是否存在 in_array(' ...

  8. mysql-multi source replication 配置

    1.关键步骤 change master to master_host='172.16.192.201', master_port, master_user='repl', master_passwo ...

  9. 在ubuntu上使用Virtual-Box安装Mininet

    使用Virtual-Box安装Mininet看上去简单,但其中也暗藏许多坑.我自己装了多次Mininet,但每次都有缺陷: mininet访问不了网络 用宿主机访问不了mininet虚拟机 最后,终于 ...

  10. ArgumentException: Getting control x's position in a group with only x controls when doing KeyDown Aborting解决方法

    标题有点长,做Editor工具时遇到的问题.最后解决了,总结下 有可能你在界面中用了键盘事件或者其他事件,导致这个报错.官方论坛有个解释比较给力LINK 我在渲染Layout和Repaint的时候加上 ...