Spring 客户端连接服务

Spring 客户端连接服务
Spring 提供了 HttpInvokerProxyFactoryBean 工厂 bean 连接服务。类似于 Hessian 的 HessianProxyFactoryBean ,配置 HttpInvokerProxyFactoryBean 时,只需指定服务的

url 以及服务实现的接口。通过使用代理, Spring 可将调用转换
Spring提供了HttpInvokerProxyFactoryBean工厂bean连接服务。类似于Hessian的HessianProxyFactoryBean,配置HttpInvokerProxyFactoryBean时,只需指定服务的url以及服务

实现的接口。通过使用代理,Spring可将调用转换成POST请求发送到指定服务。详细的配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Spring配置文件的文件头,包含dtd等信息-->
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<!-- Spring配置文件的根元素-->
<beans>
<!-- 配置测试bean,该测试bean依赖于远程服务bean-->
<bean id="test" class="lee.Test">
<!-- 配置依赖注入-->
<property name="hello">
<ref local="helloService"/>
</property>
</bean>

<!-- 配置连接远程服务的bean-->

<bean id="helloService" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
<!-- 远程服务的url-->
<property name="serviceUrl" value="http://localhost:8888/httpInvoker/remoting/helloService"/>
<!-- 远程服务所实现的接口-->
<property name="serviceInterface" value="lee.Hello"/>
</bean>
</beans>
通过上面的配置,客户端可以访问httpInvoker提供的服务,默认情况下,HttpInvokerPropxy使用J2SE的HTTP Client功能。可通过设置httpInvokerRequestExecutor属性使用

Commons HttpClient。通过对配置文件简单修改,将
<bean id="helloService" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
<!-- 远程服务的url-->
<property name="serviceUrl" value="http://localhost:8888/httpInvoker/remoting/helloService"/>
<!-- 远程服务所实现的接口-->
<property name="serviceInterface" value="lee.Hello"/>
</bean>

修改成:
<bean id="helloService" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
<!-- 远程服务的url-->
<property name="serviceUrl" value="http://localhost:8888/httpInvoker/remoting/helloService"/>
<!-- 远程服务所实现的接口-->
<property name="serviceInterface" value="lee.Hello"/>
<!-- 指定使用Commons HttpClient功能-->
<property name="httpInvokerRequestExecutor">
<bean class="org.springframework.remoting.httpinvoker.CommonsHttpInvokerRequestExecutor"/>
</property>
</bean>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值