spring-config-common.xml 2.05 KB
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">

    <bean id="pollingConnectionManager" class="org.apache.http.impl.conn.PoolingHttpClientConnectionManager">
        <property name="maxTotal" value="40"/>
        <property name="defaultMaxPerRoute" value="5"/>
    </bean>

    <bean id="httpClientBuilder" class="org.apache.http.impl.client.HttpClientBuilder"
          factory-method="create">
        <property name="connectionManager" ref="pollingConnectionManager"/>
    </bean>

    <bean id="httpClient" factory-bean="httpClientBuilder"
          factory-method="build"/>

    <!-- -->
    <bean id="clientHttpRequestFactory"
          class="org.springframework.http.client.HttpComponentsClientHttpRequestFactory">
        <constructor-arg ref="httpClient"/>
        <property name="connectTimeout" value="30000"/>
        <property name="readTimeout" value="30000"/>
    </bean>


    <bean id="commonRestTemplate" class="org.springframework.web.client.RestTemplate">
        <constructor-arg ref="clientHttpRequestFactory"/>
        <property name="messageConverters">
            <list>
                <bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
                <bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter"/>
                <bean class="org.springframework.http.converter.FormHttpMessageConverter"/>
                <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
                    <property name="supportedMediaTypes" value="application/json;charset=UTF-8"/>
                </bean>
                <bean class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter"/>
            </list>
        </property>
    </bean>

</beans>