Remoting and web services using Spring[摘自官网]
spring document url:
http://docs.spring.io/spring/docs/
Using Hessian
First we’ll have to create a new servlet in your application (this is an excerpt from 'web.xml'):
<servlet>
<servlet-name>remoting</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet> <servlet-mapping>
<servlet-name>remoting</servlet-name>
<url-pattern>/remoting/*</url-pattern>
</servlet-mapping>
ou’re probably familiar with Spring’s DispatcherServlet principles and if so, you know that now you’ll have to create a Spring container configuration resource named 'remoting-servlet.xml' (after the name of your servlet) in the 'WEB-INF' directory.
Alternatively, consider the use of Spring’s simpler HttpRequestHandlerServlet. This allows you to embed the remote exporter definitions in your root application context (by default in 'WEB-INF/applicationContext.xml'), with individual servlet definitions pointing to specific exporter beans. Each servlet name needs to match the bean name of its target exporter in this case.
In the newly created application context called remoting-servlet.xml, we’ll create a HessianServiceExporter exporting your services:
<bean id="accountService" class="example.AccountServiceImpl">
<!-- any additional properties, maybe a DAO? -->
</bean> <bean name="/AccountService" class="org.springframework.remoting.caucho.HessianServiceExporter">
<!-- 构造需要的输入参数 -->
<property name="service" ref="accountService"/>
<!-- 服务端客户端使用的接口 -->
<property name="serviceInterface" value="example.AccountService"/>
</bean>
In the latter case, define a corresponding servlet for this exporter in 'web.xml', with the same end result: The exporter getting mapped to the request path/remoting/AccountService. Note that the servlet name needs to match the bean name of the target exporter.
<servlet>
<servlet-name>accountExporter</servlet-name>
<servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class>
</servlet> <servlet-mapping>
<servlet-name>accountExporter</servlet-name>
<url-pattern>/remoting/AccountService</url-pattern>
</servlet-mapping>
to link in the service on the client, we’ll create a separate Spring container, containing the simple object and the service linking configuration bits:
<bean class="example.SimpleObject">
<property name="accountService" ref="accountService"/>
</bean> <bean id="accountService" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
<property name="serviceUrl" value="http://remotehost:8080/remoting/AccountService"/>
<property name="serviceInterface" value="example.AccountService"/>
</bean>
//假设不定义SimpleObject
//配置文件名为spring-config-client.xml
//client可以使用这样的代码调用
ApplicationContext context = new ClassPathXmlApplicationContext("spring-config-client.xml");
AccountService accountService = (AccountService)context.getBean("accountService");
//
//POJO for transport
//
public class Account implements Serializable{ private String name; public String getName(){
return name;
} public void setName(String name) {
this.name = name;
} }
//
//server and client
//
public interface AccountService { public void insertAccount(Account account); public List<Account> getAccounts(String name); }
//
//server
// the implementation doing nothing at the moment
public class AccountServiceImpl implements AccountService { public void insertAccount(Account acc) {
// do something...
} public List<Account> getAccounts(String name) {
// do something...
} }
//
//client
//
public class SimpleObject { private AccountService accountService; public void setAccountService(AccountService accountService) {
this.accountService = accountService;
} // additional methods using the accountService }
org.springframework.remoting.caucho.HessianServiceExporter - This exports the specified service as a servlet based http request handler. Hessian services exported by this class can be accessed by any hessian client.
org.springframework.remoting.caucho.HessianProxyFactoryBean - This is the factory bean for Hessian clients. The exposed service is configured as a spring bean. The ServiceUrl property specifies the URL of the service and the ServiceInterface property specifies the interface of the implemented service.

1.Client sends a message call
2.This message call is handled by a Hessian Proxy created by HessianProxyFactoryBean
3.The Hessian Proxy converts the call into a remote call over HTTP
4.The Hessian Service Adapter created by HessianServiceExporter intercepts the remote call over HTTP
5.It forwards the method call to Service
Remoting and web services using Spring[摘自官网]的更多相关文章
- Spring Boot的学习之路(02):和你一起阅读Spring Boot官网
官网是我们学习的第一手资料,我们不能忽视它.却往往因为是英文版的,我们选择了逃避它,打开了又关闭. 我们平常开发学习中,很少去官网上看.也许学完以后,我们连官网长什么样子,都不是很清楚.所以,我们在开 ...
- 【ABAP系列】SAP LSMW(摘自官网)
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP LSMW(摘自官网) 前 ...
- PEP8之常用编码规范-摘自官网
PEP8是广泛应用于Python编码中的规范,这里只会记录最重要的一部分:摘自官网 使用4个空格缩进,不要使用制表符. 4个空格是一个在小缩进(允许更大的嵌套深度)和大缩进(更容易阅读)的一种很好的折 ...
- Spring Security 官网文档学习
文章目录 通过`maven`向普通的`WEB`项目中引入`spring security` 配置 `spring security` `configure(HttpSecurity)` 方法 自定义U ...
- (五)Spring Boot官网文档学习
文章目录 SpringApplication SpringApplication 事件 `ApplicationContext ` 类型 访问传递给 `SpringApplication` 的参数 A ...
- (四)Spring Boot官网文档学习
文章目录 关于默认包的问题 加载启动类 配置 Bean管理和依赖注入 @SpringBootApplication Developer Tools 关于 Developer Tools 的一些细节 原 ...
- (二)Spring Boot 官网文档学习之入门
文章目录 Spring Boot 是什么 系统要求 Servlet 容器 Maven方式安装Spring Boot 编写第一个 Spring Boot 项目 原文:https://docs.sprin ...
- spring改版官网下载jar包, 源代码和文档
从网上找了一些方法,现在都整理了一下,有简单粗暴的,也有百转回肠的(详细,直接从官网一步一步的进入下载页),希望大家根据自己的喜好可以找到的真爱. 方法一:(简单粗暴直接) http://repo.s ...
- (三)Spring Boot 官网文档学习之默认配置
文章目录 继承 `spring-boot-starter-parent` 覆盖默认配置 启动器 原文地址:https://docs.spring.io/spring-boot/docs/2.1.3.R ...
随机推荐
- VC调试闪退解决办法
在VC2010调试或执行EXE文件时,程序运行结束后自动退出了,想看到打印 可以采用几种方法: 1.按ctrl+F5只执行不调试 2.在cmd中手动调用 而不是直接点 3.加入getchar #in ...
- Mac Pro 利用PHP导出SVN新增或修改过的文件
先前在 Windows 操作系统下,习惯用 TortoiseSVN 导出新增或修改过的文件([相当实用]如何让TortoiseSVN导出新增或修改过的文件 ),最近换成了 Mac Pro 笔记本电脑, ...
- Android滑动菜单特效实现,仿人人客户端侧滑效果,史上最简单的侧滑实现
http://blog.csdn.net/guolin_blog/article/details/8714621 http://blog.csdn.net/lmj623565791/article/d ...
- 基于jquery fly插件实现加入购物车抛物线动画效果,jquery.fly.js
在购物网站中,加入购物车的功能是必须的功能,有的网站在用户点击加入购物车按钮时,就会出现该商品从点击出以抛物线的动画相似加入购物车,这个功能看起来非常炫,对用户体验也有一定的提高.下面介绍基于jque ...
- make menuconfig error 解决方法记录
新建的一个虚拟机,发现make menuconfig 后会出错,查了一下是缺少一些库. 这个错误已经错了两次了,我不希望第三次出现了还想不起来,所以特此记录. # 错误信息: make[2]: *** ...
- 数组去重及数组的prototype原型
Array.prototype.check= function(){ for(var i=0;i<this.length;i++){ for(var j=i+1;j<this.length ...
- C语言 链表排序
#include <stdio.h> #include <stdlib.h> #include <assert.h> typedef struct node{ in ...
- ASP.NET MVC随想录——锋利的KATANA
正如上篇文章所述那样,OWIN在Web Server与Web Application之间定义了一套规范(Specs),意在解耦Web Server与Web Application,从而推进跨平台的实现 ...
- 【python】点分十进制ip与数字互转
来源:http://www.cnblogs.com/vovlie/archive/2012/10/17/2727029.html 利用lambda表达式,非常简洁 int_to_ip = lambda ...
- nmon的安装
安装 mkdir /usr/local/nmon cd /usr/local/nmon wget http://sourceforge.net/projects/nmon/files/nmon_lin ...