Spring中使用Hessian暴露服务
来源:互联网 发布:php 执行git命令 编辑:程序博客网 时间:2024/05/22 06:59
Spring Framework中有对RMI,Hessian,Burlap,JAX-RPC,JAX-WS.JMS的服务支持,更方便的用于开发异构的服务系统,自身也有HTTPinvoker技术提供远端服务.
以下示例来自SpringFramework-doc文档, 我们先建立用于测试的实体、服务接口类:public class Account implements Serializable{
private String name;
public String getName(){
return name;
}
public void setName(String name) {
this.name = name;
}
}
public interface AccountService {
public void insertAccount(Account account);
public List<Account> getAccounts(String name);
}
// 服务的具体实现类
public class AccountServiceImpl implements AccountService {
public void insertAccount(Account acc) {
// do something...
}
public List<Account> getAccounts(String name) {
// do something...
}
}
下面我们就用caucho公司的hessian技术来提供一个基于HTTP的服务:
首先需要下载hessian包:http://www.caucho.com.
然后配置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>
建立spring xml 配置remoting-servlet.xml通过Spring包装一个接口为hessian服务:
<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>
这样 hessian的服务就通过'http://HOST:8080/remoting/AccountService'.来暴露给客户端调用
在客户端中调用
通过Spring来配置测试BEAN
public class SimpleObject {
private AccountService accountService;
public void setAccountService(AccountService accountService) {
this.accountService = accountService;
}
// additional methods using the accountService
}
<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>
servicePort属性被省略了(默认为0)。这意味着匿名端口将用于与服务通信。
相关阅读:
Spring3 RMI 使用介绍
PHP调用Hessian Java 远端WEB服务
- Spring中使用Hessian暴露服务
- 使用PHPHessian调用Java Spring Hessian暴露服务
- 通过注解自动暴露Hessian服务
- Spring RMI暴露服务
- Spring使用远程服务之Hessian
- Spring使用远程服务之Hessian
- hessian远程调用及spring中使用hessian
- Spring整合Hessian服务
- 在Spring中使用Hessian Remoting技术。
- 在Spring中使用Hessian Remoting技术
- 在Spring中使用Hessian Remoting技
- 在Spring中使用Hessian Remoting技术
- Spring 集成hessian进行接口的暴露和访问
- hessian + spring 使用
- Dubbo框架初探【用Spring配置声明暴露服务(可以使用multicast广播注册中心暴露服务地址或者使用zookeeper注册中心暴露服务地址)、加载Spring配置,启动服务】
- Dubbo框架初探【用Spring配置声明暴露服务(可以使用multicast广播注册中心暴露服务地址或者使用zookeeper注册中心暴露服务地址)、加载Spring配置,启动服务】
- 使用Hessian提供远程服务
- 在Spring中使用Hessian Remoting技术-------实例附件源码
- XSS进阶一
- 一网打尽,123个免费数字取证工具收藏列表
- Swig编译C代码供java调用实例
- java.net.SocketException: select failed
- 解决Myeclipse下Debug出现Source not found以及sql server中导入数据报错
- Spring中使用Hessian暴露服务
- 2012年"浪潮杯"山东省第三届ACM大学生程序设计竞赛--n a^o7 !
- 《深入理解Java虚拟机》学习小记一之自动内存管理机制(一)
- android 异步加载网络图片
- C++ union 和struct的使用
- Win7忘记密码如何破解
- [android][studio] build a project
- C#2.0泛型编程之强制类型转换、继承和泛型
- 《深入理解Java虚拟机》学习小记一之自动内存管理机制(二)