默认情况下,客户端的HttpInvokerProxy使用J2SE的HTTP Client来建立连接,即org.springframework.remoting.httpinvoker.SimpleHttpInvokerRequestExecutor,可以通过设置httpInvokerRequestExecutor属性来改变默认配置,spring提供了另外一种HttpClient,org.springframework.remoting.httpinvoker.CommonsHttpInvokerRequestExecutor。
修改配置如下:
<bean id="httpService"
class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
<property name="serviceUrl">
<value>http://vm.netqin.com:4080/ucs/service/httpService</value>
</property>
<property name="serviceInterface" value="com.netqin.baike.service.UcService">
</property>
<property name="httpInvokerRequestExecutor">
<bean
class="org.springframework.remoting.httpinvoker.CommonsHttpInvokerRequestExecutor" />
</property>
</bean>
需要在项目中引入两个jar包:
commons-codec-x.x.jar
commons-httpclient-x.x.x.jar
CommonsHttpInvokerRequestExecutor具有HTTP connection pooling,不过通过使用jmeter进行压力测试发现,SimpleHttpInvokerRequestExecutor性能高于CommonsHttpInvokerRequestExecutor