记得在spring主配置文件里加载此文件
httpclients:
<bean id="httpClientConnectionManager" class="org.apache.http.impl.conn.PoolingHttpClientConnectionManager" destroy-method="shutdown">
<!-- 设置最大连接数 -->
<property name="maxTotal" value="${http.maxTotal}"/>
<!-- 设置每个主机地址的并发数 -->
<property name="defaultMaxPerRoute" value="${http.defaultMaxPerRoute}"/>
</bean>
<bean id="httpClientBuilder" class="org.apache.http.impl.client.HttpClientBuilder">
<property name="connectionManager" ref="httpClientConnectionManager"/>
</bean>
<!--
通过httpClientBuilder得到httpClient对象,并且要设置httpClient为多利模式
-->
<bean id="httpClient" class="org.apache.http.impl.client.CloseableHttpClient" factory-bean="httpClientBuilder" factory-method="build" scope="prototype"/>
<!-- 构造请求参数 -->
<bean id="requestConfigBuilder" class="org.apache.http.client.config.RequestConfig.Builder">
<property name="connectTimeout" value="${http.connectTimeout}"/>
<property name="connectionRequestTimeout" value="${http.connectionRequestTimeout}"/>
<property name="socketTimeout" value="${http.socketTimeout}"/>
<property name="staleConnectionCheckEnabled" value="${http.staleConnectionCheckEnabled}"/>
</bean>
<bean id="requestConfig" class="org.apache.http.client.config.RequestConfig" factory-bean="requestConfigBuilder" factory-method="build"/>
<!-- 清理无效连接 -->
<!-- <bean class="com.shangji.common.service.IdleConnectionEvictor" destroy-method="shutdown">
<constructor-arg index="0" ref="httpClientConnectionManager"/>
</bean> -->
redis:
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<!--#最大分配的对象数
maxActive=1024//后继版本使用maxTotal属性
#最大能够保持空闲状态的对象数
maxIdle=200
#当池内没有返回对象时,最大等待时间
maxWaitMillis=1000
#在borrow(借用/作用)一个jedis实例时,是否提前进行validate操作;如果为true,则得到的jedis实例均是可用的;
testOnBorrow=true
-->
<property name="maxTotal" value="${jedis.maxTotal}" />
<property name="maxIdle" value="${jedis.maxIdle}" />
<property name="maxWaitMillis" value="${jedis.maxWaitMillis}" />
<property name="testOnBorrow" value="${jedis.testOnBorrow}" />
</bean>
<bean id="jedisConnectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="hostName" value="${redis.host}" />
<property name="port" value="${redis.port}" />
<property name="poolConfig" ref="jedisPoolConfig" />
</bean>
<bean class="org.springframework.data.redis.core.StringRedisTemplate"
p:connection-factory-ref="jedisConnectionFactory" />
<!-- <context:component-scan base-package="com.shangji" /> -->