<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">

<!-- 定义连接管理器 -->
<bean />
</bean>

<!-- 定义Httpclient构造器 -->
<bean />
</bean>

<!-- 定义Httpclient对象 -->
<bean class="org.apache.http.impl.client.CloseableHttpClient" factory-bean="httpClientBuilder" factory-method="build" scope="prototype" />

<!-- 请求参数的构造器 -->
<bean />
</bean>

<!-- 定义请求参数 -->
<bean class="org.apache.http.client.config.RequestConfig" factory-bean="requestConfigBuilder" factory-method="build" />

<!-- 定期关闭无效连接 -->
<bean class="com.taotao.web.httpclient.IdleConnectionEvictor">
  <constructor-arg index="0" ref="connectionManager" />
</bean>

</beans>

spring整合的原则:以httpclient与spring整合为例

httpclient与spring的整合步骤
1,首先在相关项目或者模块的资源文件夹下创建一个xml文科件
applicationContext-httpclient.xml,通常这个文件放在spring文件夹中(applicationContext这个拼错,不要问我为什么这样说!!!)
2,整合原则:把什么样的那个托管给spring,让spring去管理
3,写一个bean,看这个对象是怎么来的
如果该对象是经过build()出来的,那么一般就表示是工厂出来的,需要配置工厂,比如下面这样
<!-- 定义Httpclient对象 -->
<bean class="org.apache.http.impl.client.CloseableHttpClient"
factory-bean="httpClientBuilder" factory-method="build" scope="prototype" />
4,如果spring中没有该对象.那么就需要定义一个该工厂对象,如果有参数,还要设置参数
<!-- 定义Httpclient构造器 -->
<bean />
</bean>

 

相关文章:

  • 2021-11-30
  • 2021-07-05
  • 2021-12-16
  • 2021-11-01
  • 2022-12-23
  • 2021-07-25
  • 2021-10-27
猜你喜欢
  • 2021-11-22
  • 2022-12-23
  • 2022-02-08
  • 2022-12-23
  • 2021-05-02
  • 2021-12-20
  • 2021-10-14
相关资源
相似解决方案