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 ...
随机推荐
- r-cnn学习(六):RPN及AnchorTargetLayer学习
RPN网络是faster与fast的主要区别,输入特征图,输出region proposals以及相应的分数. # ------------------------------------------ ...
- ngCloak 实现 Angular 初始化闪烁最佳实践
在做angular的SPA开发时,我们经常会遇见在如Chrome这类能够快速解析的浏览器上出现表达式({{ express }} ),或者是模块(div)的闪烁.对于这个问题由于JavaScript去 ...
- AJAX工作原理及其优缺点
1.什么是AJAX?AJAX全称为"Asynchronous JavaScript and XML"(异步JavaScript和XML),是一种创建交互式网页应用的网页开发技术.它 ...
- js跨域解决方案(转载)
1.什么是跨域 我们经常会在页面上使用ajax请求访问其他服务器的数据,此时,客户端会出现跨域问题. 跨域问题是由于javascript语言安全限制中的同源策略造成的. 简单来说,同源策略是指一段脚本 ...
- jquery 赋值文本框输入框
jQuery("#mrId option[value='" + extValue + "']").attr("selected", true ...
- sqlserver中分区函数 partition by的用法
partition by关键字是分析性函数的一部分,它和聚合函数(如group by)不同的地方在于它能返回一个分组中的多条记录,而聚合函数一般只有一条反映统计值的记录, partition by ...
- System Error Codes
很明显,以下的文字来自微软MSDN 链接http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx M ...
- Scrapy002-框架安装
Scrapy002-框架安装 @(Spider)[POSTS] 这里我使用的是Python3.x, 1. Ubuntu上安装 在安装Scrapy之前,首先需要确定环境和版本: Ubuntu16.04 ...
- go:匿名函数与闭包
一.匿名函数 定义:没有函数名的函数. 作用:在go语言中目前了解的作用就是用于构成闭包. *注:由于javascript不存在块级作用域,故匿名函数常用来包含代码以不污染全局命名空间,运行后销毁环境 ...
- java面试题及答案(转载)
JAVA相关基础知识1.面向对象的特征有哪些方面 1.抽象:抽象就是忽略一个主题中与当前目标无关的那些方面,以便更充分地注意与当前目标有关的方面.抽象并不打算了解全部问题,而只是选择其中的一部分,暂时 ...