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 ...
随机推荐
- 个性化设置phpMyAdmin,去掉“以树形显示数据库”,禁用“发送错误报告”
个性化设置phpMyAdmin 在使用phpMyAdmin 3.5.8.2时,发现: 如果数据库有相同的前缀,左边数据库导航会把前缀合并,即所谓的“以树形显示数据库”,真的有点不习惯,如下图所示: 不 ...
- Swift3.0P1 语法指南——下标
原档:https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programmi ...
- 小知识点总结HTML、CSS、JavaScript(一)
1.给元素同时设置背景色和背景图的时候,当背景色写在背景图后面,背景色会覆盖背景图未覆盖的位置 如background:url(); background-color:red; 2.当需求一段文字右对 ...
- access日期与sql server日期区别
如选取一段时间内的数据,time1和time2是时间起始字符串,则 sql server命令: string strSQL=" 日期 >='"+time1+"' A ...
- nginx+ISS 负载均衡 快速入门
第一:下载 http://pan.baidu.com/s/1dDwapbF 或者官网 http://nginx.org/en/download.html 启动服务: 直接运行nginx.exe,缺点控 ...
- 《C#本质论》读书笔记(16)构建自定义集合
16.1 更多集合接口 集合类(这里指IEnumerable层次结构)实现的接口层次结构 16.1.1 IList<T>与IDictionary<TKey,TValue> 字典 ...
- xml schema xmlns xmlns:xsi xsi:schemaLocation targetnamespace
先上一段xml文档 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="htt ...
- Leetcode: Surrounded regions
Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'. A region is captured ...
- OpenCv全景图像拼接
http://my.oschina.net/xiaot99/blog/226589 http://blog.csdn.net/chenjiazhou12/article/details/2282548 ...
- UWP 解决Webview在Pivot里面无法左右滑动的问题
//为了解决webview在PivotItem里面,阻止pivot左右滑动. if (webView != null) { rootGrid.Children.Remove(webView); web ...