Spring HTTP Invoker使用介绍
来源:互联网 发布:槽钢抗弯强度计算软件 编辑:程序博客网 时间:2024/05/23 13:56
RMI:使用JRMP协议(基于TCP/IP),不允许穿透防火墙,使用JAVA系列化方式,使用于任何JAVA应用之间相互调用。
Hessian:使用HTTP协议,允许穿透防火墙,使用自己的系列化方式,支持JAVA、C++、.Net等跨语言使用。
Burlap: 与Hessian相同,只是Hessian使用二进制传输,而Burlap使用XML格式传输(两个产品均属于caucho公司的开源产品)。
Spring HTTP Invoker: 使用HTTP协议,允许穿透防火墙,使用JAVA系列化方式,但仅限于Spring应用之间使用,即调用者与被调用者都必须是使用Spring框架的应用。
/* <p><b>HTTP invoker is the recommended protocol for Java-to-Java remoting.</b>* It is more powerful and more extensible than Hessian and Burlap, at the* expense of being tied to Java. Nevertheless, it is as easy to set up as* Hessian and Burlap, which is its main advantage compared to RMI.*/Spring一定希望大家尽量使用它的产品,但实际项目中我们还是要根据需求来决定选择哪个框架,下面我们来看看Spring HTTP Invoker的使用。
服务端配置:
服务声明:
在Spring配置文件中声明一个HttpInvokerServiceExporter类的bean,共三部分:
--服务名称(如helloExporter)
--服务类型(如com.stevex.demo.HelloService)
--服务实现类,一般引用其它bean(如helloService)
<bean name="helloExporter" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter"> <property name="service" ref="helloService"></property> <property name="serviceInterface" value="com.stevex.demo.HelloService"> </property></bean>
2.服务URL关联:
在web.xml中声明一个与服务与服务名称同名的Servlet(当然这个Servlet类Spring已经提供即HttpRequestHandlerServlet,这家伙的作用就是直 接把强求扔给同名的bean),然后声明servlet-mapping将其map到指定URL,这样客户就可以通过这个URL访问到对应服务。
<servlet> <servlet-name>helloExporter</servlet-name> <servlet-class> org.springframework.web.context.support.HttpRequestHandlerServlet </servlet-class> </servlet> <servlet-mapping> <servlet-name>helloExporter</servlet-name> <url-pattern>/remoting/HelloService</url-pattern></servlet-mapping>
客户端配置:
<bean id="remoteHelloService" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean"> <property name="serviceUrl" value="http://localhost:8080/demo/remoting/HelloService" /> <property name="serviceInterface" value="com.stevex.demo.HelloService" /></bean>
服务端实现:
@Service("helloService")public class HelloServiceImpl implements HelloService { @Override public String hello() { return "Hello Stevex, I am invoked by Spring HTTP Invoker!"; }}public interface HelloService { public String hello();}
客户端实现:
public class HelloClient { public static void main(String[] args) { GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); ctx.load("classpath:http-invoker-app-context.xml"); ctx.refresh(); HelloService helloService = ctx.getBean("remoteHelloService", HelloService.class); System.out.println(helloService.hello()); }}
客户端配置:
服务端实现:
0 0
- Spring HTTP Invoker使用介绍
- Spring HTTP Invoker使用介绍
- Spring HTTP Invoker使用介绍
- Spring HTTP Invoker使用介绍
- Spring HTTP Invoker使用介绍
- Spring HTTP Invoker使用
- Spring HTTP Invoker使用
- spring(基础十) Spring HTTP Invoker使用介绍
- Spring Http Invoker使用简介
- Spring Http Invoker使用简介
- Spring Http Invoker使用简介
- 使用Spring HTTP invoker进行远程调用
- Spring发布和使用Http Invoker
- Spring HTTP invoker简介
- Spring HTTP invoker简介
- Spring HTTP invoker简介
- Spring HTTP invoker简介
- Spring HTTP invoker简介
- Python2.7 + beautifulSoup 4.4.1 安装配置
- bom表
- C# 实用文件存储
- sdutoj 3302 效率至上
- Android Studio gradle更新地址
- Spring HTTP Invoker使用介绍
- 小巴孩 母亲节祝福
- Timer定时器
- 专访|腾讯、阿里、adidas的服务方UID WORKS
- 拍照权限被第三方禁用
- UNITY Rigidbody 参数设置
- Service
- (3)使用Redis作为消息队列服务场景应用案例
- Java基础——IO