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

    <!-- rest template -->
    <bean id="service-httpClient" class="com.yoho.core.common.http.HttpClientsFactory">
        <property name="connectionRequestTimeout" value="6000"/>
        <property name="socketTimeout" value="1900"/>
        <property name="connectionTimeout" value="6000"/>
        <property name="maxTotal" value="30"/>
        <property name="defaultMaxPerRoute" value="10"/>
    </bean>
    <bean id="service-clientHttpRequestFactory"
          class="org.springframework.http.client.HttpComponentsClientHttpRequestFactory">
        <constructor-arg ref="service-httpClient"/>
    </bean>

    <bean id="service-restTemplate" class="org.springframework.web.client.RestTemplate">
        <constructor-arg ref="service-clientHttpRequestFactory"/>
        <property name="messageConverters">
            <list>
                <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>
                <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                    <property name="supportedMediaTypes">
                        <list>
                            <value>text/plain;charset=UTF-8</value>
                            <value>text/plain;charset=utf-8</value>
                            <value>text/html;charset=UTF-8</value>
                            <value>text/html;charset=utf-8</value>
                            <value>text/xml;charset=GBK</value>
                            <value>text/xml;charset=gbk</value>
                        </list>
                    </property>
                </bean>
                <bean class="org.springframework.http.converter.ResourceHttpMessageConverter"/>
                <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>
            </list>
        </property>
    </bean>
    
    <bean id="yhRestCaller" class="com.yoho.global.common.rest.client.YHRestCaller">
        <property name="restTemplate" ref="service-restTemplate"/>
        <property name="yhbUrl" value="${yhb_api_url:http://api.yoho.cn}"/>  
        <property name="yhbClientType" value="${yhb_client_type:web}"/> 
        <property name="yhbClientKey" value="${yhb_client_key:0ed29744ed318fd28d2c07985d3ba633}"/>
        <property name="keyConfigMap" ref="securityConfigMap" />
    </bean>

    <bean id="securityConfigMap" class="org.springframework.beans.factory.config.YamlMapFactoryBean">
        <property name="resources">
            <list>
                <value>classpath:security-key.yml</value>
            </list>
        </property>
    </bean>
</beans>