1. 简单介绍httpInvoker的实现
Spring中,HTTPInvoker(HTTP调用器)是通过基于HTTP协议的分布式远程调用解决方案.
1.1客户端
a.向服务器发送远程调用请求:远程调用信息——>封装为远程调用对象——>序列化写入到远程调用HTTP请求中——>向服务器端发送。
b.接收服务器端返回的远程调用结果:服务器端返回的远程调用结果HTTP响应——>反序列化为远程调用结果对象。
1.2服务端
a. 接收客户端发送的远程调用请求:客户端发送的远程调用HTTP请求——>反序列化为远程调用对象——>调用服务器端目标对象的目标方法处理。
b.向客户端返回远程调用结果: 服务器端目标对象方法的处理结果——>序列化写入远程调用结果HTTP响应中——>返回给客户端。
2. 具体如何配置
2.1 客户端配置
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE beans PUBLIC
"-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans default-autowire="byName">
......
<bean id="testService" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
<property name="serviceUrl" value="http://127.0.0.1:8300/testService.service"/>
<property name="serviceInterface" value="com.xxx.biz.service.TestService"/>
</bean>
</beans>
2.2 服务端配置
<pre name="code" class="html"><?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE beans PUBLIC
"-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans default-autowire="byName">
....
<bean id="testService" class="com.xxxx.biz.service.impl.TestServiceImpl"></bean>
<bean name="/testService.service" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
<property name="service" ref="testService" />
<property name="serviceInterface" value="com.xxx.biz.service.TestService" />
</bean>
</beans>
web.xml配置:
<servlet>
<servlet-name>remoting</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-o