读书人

Spring 客户端联接服务

发布时间: 2012-09-23 10:28:11 作者: rapoo

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" 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" value="http://localhost:8888/httpInvoker/remoting/helloService"/>
<!-- 远程服务所实现的接口-->
<property name="serviceInterface" value="lee.Hello"/>
</bean>

修改成:
<bean id="helloService" 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>

读书人网 >软件架构设计

热点推荐