Bean is not formed for datasource in Spring MVC Project - spring

I am facing error "Property datasource is required".
Below is the configuration in dao-beans xml.
<bean id="Template" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:/comp/env/jdbc/TEMPLATES" />
</bean>
<bean id="languageDao" class="com.test.daoImpl.LanguageDAOImpl"
init-method="init">
<property name="cspLanguageGet" value="csp_LANGUAGE_Get" />
</bean>
Class has the following configurations:
private DataSource Template;
private SimpleJdbcCall languageGet;
private String cspLanguageGet;
#Autowired
#Qualifier("Template")
public void setTemplate(DataSource Template) {
this.Template = Template;
}
#Required
public void setCspLanguageGet(String cspLanguageGet) {
this.cspLanguageGet = cspLanguageGet;
}
public void init() {
this.languageGet = new SimpleJdbcCall(Template).withProcedureName(cspLanguageGet);
this.languageGet.compile();
}
I tried with the many solutions which I found over but no luck.I can't use since my java version is 1.8
Below is the error stack trace.
java.lang.IllegalArgumentException: Property 'dataSource' is required
at org.springframework.jdbc.support.JdbcAccessor.afterPropertiesSet(JdbcAccessor.java:134)
at org.springframework.jdbc.core.JdbcTemplate.<init>(JdbcTemplate.java:165)
at org.springframework.jdbc.core.simple.AbstractJdbcCall.<init>(AbstractJdbcCall.java:87)
at org.springframework.jdbc.core.simple.SimpleJdbcCall.<init>(SimpleJdbcCall.java:69)
at com.aexp.travel.docdelivery.tcapp.daoImpl.LanguageDAOImpl.init(LanguageDAOImpl.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
Context.xml deployed in tomcat has the following configuration:
<Resource
name="jdbc/TEMPLATES"
auth="Container"
type="javax.sql.DataSource"
maxActive="100"
maxIdle="30"
maxWait="10000"
driverClassName="net.sourceforge.jtds.jdbc.Driver"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
url="jdbc:jtds:sqlserver://gtwtdwdbsqlv001.gbt.gbtad.com:1433;databaseName=Template"
username="Test"
password="*******"
/>
I am stuck in this from past 3 days.Not able to resolve this.Can anyone pls help me to understand where it is going wrong

It depends which version of Spring you are using but You may include DataSoure bean as shown below
<bean name="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="org.h2.Driver" />
<property name="url" value="jdbc:h2:file:C:/temp/test" />
<property name="username" value="sa" />
<property name="password" value="" />
<property name="initialSize" value="2" />
<property name="maxActive" value="5" />
</bean>
OR
#Bean
public DataSource getDataSource() {
DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create();
dataSourceBuilder.driverClassName("org.h2.Driver");
dataSourceBuilder.url("jdbc:h2:file:C:/temp/test");
dataSourceBuilder.username("sa");
dataSourceBuilder.password("");
return dataSourceBuilder.build();
}

Related

Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'dataSource' is required [duplicate]

I am facing error "Property datasource is required".
Below is the configuration in dao-beans xml.
<bean id="Template" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:/comp/env/jdbc/TEMPLATES" />
</bean>
<bean id="languageDao" class="com.test.daoImpl.LanguageDAOImpl"
init-method="init">
<property name="cspLanguageGet" value="csp_LANGUAGE_Get" />
</bean>
Class has the following configurations:
private DataSource Template;
private SimpleJdbcCall languageGet;
private String cspLanguageGet;
#Autowired
#Qualifier("Template")
public void setTemplate(DataSource Template) {
this.Template = Template;
}
#Required
public void setCspLanguageGet(String cspLanguageGet) {
this.cspLanguageGet = cspLanguageGet;
}
public void init() {
this.languageGet = new SimpleJdbcCall(Template).withProcedureName(cspLanguageGet);
this.languageGet.compile();
}
I tried with the many solutions which I found over but no luck.I can't use since my java version is 1.8
Below is the error stack trace.
java.lang.IllegalArgumentException: Property 'dataSource' is required
at org.springframework.jdbc.support.JdbcAccessor.afterPropertiesSet(JdbcAccessor.java:134)
at org.springframework.jdbc.core.JdbcTemplate.<init>(JdbcTemplate.java:165)
at org.springframework.jdbc.core.simple.AbstractJdbcCall.<init>(AbstractJdbcCall.java:87)
at org.springframework.jdbc.core.simple.SimpleJdbcCall.<init>(SimpleJdbcCall.java:69)
at com.aexp.travel.docdelivery.tcapp.daoImpl.LanguageDAOImpl.init(LanguageDAOImpl.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
Context.xml deployed in tomcat has the following configuration:
<Resource
name="jdbc/TEMPLATES"
auth="Container"
type="javax.sql.DataSource"
maxActive="100"
maxIdle="30"
maxWait="10000"
driverClassName="net.sourceforge.jtds.jdbc.Driver"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
url="jdbc:jtds:sqlserver://gtwtdwdbsqlv001.gbt.gbtad.com:1433;databaseName=Template"
username="Test"
password="*******"
/>
I am stuck in this from past 3 days.Not able to resolve this.Can anyone pls help me to understand where it is going wrong
It depends which version of Spring you are using but You may include DataSoure bean as shown below
<bean name="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="org.h2.Driver" />
<property name="url" value="jdbc:h2:file:C:/temp/test" />
<property name="username" value="sa" />
<property name="password" value="" />
<property name="initialSize" value="2" />
<property name="maxActive" value="5" />
</bean>
OR
#Bean
public DataSource getDataSource() {
DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create();
dataSourceBuilder.driverClassName("org.h2.Driver");
dataSourceBuilder.url("jdbc:h2:file:C:/temp/test");
dataSourceBuilder.username("sa");
dataSourceBuilder.password("");
return dataSourceBuilder.build();
}

Bean property 'entityManager' is not writable or has an invalid setter method (using Spring and Hibernate)

Spring and hibernate are both new tools for me and I struggle a bit using both at the same time.
spring.xml :
<bean id="my.supervisionFramesProcess" class="supervision.frames.SupervisionFramesProcess"
init-method="startup" destroy-method="shutdown">
<property name="SupervisionDAO">
<bean class="supervision.dao.jpa.JpaSupervisionDao">
<property name="entityManager" ref="my.entity-manager-factory" />
</bean>
</property>
</bean>
<bean id="my.dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://XXXX/supervision?autoReconnect=true" />
<property name="username" value="***" />
<property name="password" value="***" />
<property name="maxIdle" value="5" />
<property name="maxActive" value="100" />
<property name="maxWait" value="30000" />
<property name="testOnBorrow" value="true" />
<property name="validationQuery" value="SELECT 1" />
</bean>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"></bean>
<bean id="my.entity-manager-factory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceXmlLocation" value="classpath*:META-INF/persistence.xml" />
<property name="dataSource" ref="my.dataSource" />
<property name="persistenceUnitName" value="SUPERVISION-1.0" />
</bean>
JpaSupervisionDao.xml :
#PersistenceContext(unitName = "SUPERVISION-1.0")
private EntityManager entityManager;
public JpaSupervisionDao() {
if (logger.isDebugEnabled())
logger.debug("New instance DAO : " + this);
}
protected void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager;
}
protected EntityManager getEntityManager() {
return entityManager;
}
#Override
public SupervisionDbObject selectSupervisionDbObject(SupervisionDbObject supervision) {
Query query = getEntityManager().createQuery(SELECT_SUPERVISION);
}
persistence.xml :
<persistence-unit name="SUPERVISION-1.0">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>supervision.dao.SupervisionDbObject</class>
</persistence-unit>
Using JDBC, my DataSource can be instanciated and is fully working but using Hibernate and the entityManager, i only get an error :
Bean property 'entityManager' is not writable or has an invalid setter method.
I have tried to use the EntityManagerFactory object instead but the same error occurs.
Can someone help me out ?
The addition of the <context:annotation-config/> fixed my issue thanks to M. Deinum's answer.
If this can help someone else, I also had an issue with an import, I was importing
org.hibernate.annotations.Entity instead of javax.persistence.Entity.

Spring MVC, Spring Batch load multiple DataSource properties from database

I have the below configuration of my db-config.xml file in several applications in work. We are using Spring Batch and each app is harvesting data from several external DB's. Everything is working fine but the problem is that all apps are deployed on different servers and every time when the password expires for one of the "Data sources", we have to go on each server and change the password manually on the db-config file for each application.
Since all applications are using more or less the same Data Sources for harvesting (about 9 in total) I am currently looking at some alternatives, so rather then declaring the "Harvest Data sources" into the db-config.xml file to place all properties into a DB table and load the properties from there. When a password expire we do the change in one single place rather then x places.
I would really appreciate any pointers in the right direction just to get started...
Sample of my db-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
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-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.ibm.db2.jcc.DB2Driver"></property>
<property name="url" value="jdbc:db2://1.111.1.11:50000/EX1"></property>
<property name="username" value="xxxxx" />
<property name="password" value="xxxxx" />
</bean>
<bean class="com.mchange.v2.c3p0.ComboPooledDataSource" id="ef_DataSource">
<property name="driverClass" value="com.ibm.db2.jcc.DB2Driver"></property>
<property name="acquireIncrement" value="5"></property>
<property name="maxIdleTime" value="3600"></property>
<property name="maxPoolSize" value="15"></property>
<property name="minPoolSize" value="5"></property>
<property name="numHelperThreads" value="3"></property>
<property name="unreturnedConnectionTimeout" value="3600"></property>
<property name="idleConnectionTestPeriod" value="100"></property>
<property name="jdbcUrl" value="jdbc:db2://2.222.2.22:50000/EX2"></property>
<property name="user" value="xxxxx" />
<property name="password" value="xxxxxx" />
</bean>
<!-- Harvest Data sources -->
<bean class="org.springframework.jdbc.datasource.DriverManagerDataSource" id="rep1">
<property name="driverClassName" value="com.ibm.db2.jcc.DB2Driver"></property>
<property name="url" value="jdbc:db2://1.11.11.111:60000/REPONE"></property>
<property name="username" value="xxxxxxxx" />
<property name="password" value="xxxxxxxx" />
</bean>
<bean class="org.springframework.jdbc.datasource.DriverManagerDataSource" id="rep4">
<property name="driverClassName" value="com.ibm.db2.jcc.DB2Driver"></property>
<property name="url" value="jdbc:db2://22.444.44.44:50000/REPTWO"></property>
<property name="username" value="xxxxxxxx"></property>
<property name="password" value="xxxxxxxx"></property>
</bean>
<bean class="org.springframework.jdbc.datasource.DriverManagerDataSource" id="rep5">
<property name="driverClassName" value="com.ibm.db2.jcc.DB2Driver"></property>
<property name="url" value="jdbc:db2://555.55.55.55:50000/REPTHREE"></property>
<property name="username" value="xxxxxxxx" />
<property name="password" value="xxxxxxxx" />
</bean>
<!-- More Harvest Data sources -->
Sample of the AbstractImportTasklet java class extended by all Tasklets classes
#Component
public abstract class AbstractImportTasklet implements ResourceLoaderAware, InitializingBean, Tasklet{
private ResourceLoader resourceLoader;
private JdbcTemplate jdbcTemplate;
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
private DataSource dataSource;
#Autowired
AmDbDAO dao;
#Autowired
protected JobExplorer jobExplorer;
public AbstractImportTasklet() {
super();
}
#Override
public void setResourceLoader(ResourceLoader resourceLoader) {
this.resourceLoader = resourceLoader;
}
public JdbcTemplate getJdbcTemplate() {
return jdbcTemplate;
}
public NamedParameterJdbcTemplate getNamedParameterJdbcTemplate(){
return namedParameterJdbcTemplate;
}
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
public void setNamedParameterJdbcTemplate(NamedParameterJdbcTemplate namedParameterJdbcTemplate){
this.namedParameterJdbcTemplate = namedParameterJdbcTemplate;
}
public DataSource getDataSource() {
return dataSource;
}
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
}
#Override
public void afterPropertiesSet() throws Exception {
/*TimeZone.setDefault(TimeZone.getTimeZone("UTC"));*/
if(dataSource != null){
this.jdbcTemplate = new JdbcTemplate(dataSource);
this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
}
}
}
One of the possible approach would be to add a step at the beginning who would read the database containing the informations on the other ones (if I understood your use case correctly). This step would then load the results in the JobExecutionContext. The results would be used in the definition of the datasources.
Here's an example (step) :
public class LoadDatasources implements Tasklet {
public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {
// Query database here
[...]
// Save results in context
chunkContext.getStepContext().getJobExecutionContext().put(key, value)
return null;
}
}
XML configuration of the datasources :
<bean class="org.springframework.jdbc.datasource.DriverManagerDataSource" step="scope">
<property name="driverClassName" value="#{jobExecutionContext['datasource1.driver']}"></property>
<property name="url" value="#{jobExecutionContext['datasource1.url']}"></property>
<property name="username" value="#{jobExecutionContext['datasource1.username']}"></property>
<property name="password" value="#{jobExecutionContext['datasource1.password']}"></property>
</bean>
This is the exact use case that Spring Cloud's Configuration Server solves. It allows you to configure things, like datasources, in a central repository. From there, you can refresh the configuration of the applications using it. You can read more about the Spring Cloud Configuration Server in the documentation here: https://github.com/spring-cloud-samples/configserver

spring Multi DataSource #Service annotation with existing error

I have a code that is an error in the Spring Framework
Error Cause I know
So I do not know how to solve it the question.
I am being used with mybatis library
I had multi DataSource of two Account DataBase
I created a root-context.xml
-----------------------root-context.xml -----------------------------------------------------------
Oracle Account 1 Test1
<bean id="dataSourceTest1" class="org.apache.commons.dbcp.BasicDataSource" destroy-m
ethod="close">
<property name="driverClassName" value="net.sf.log4jdbc.DriverSpy"/>
<property name="url" value="jdbc:log4jdbc:oracle:thin:#111.111.1111.1111:1111:Test1"/>
<property name="username" value="TEST1"/>
<property name="password" value="TEST1"/>
<property name="maxIdle" value="200"/>
<property name="maxActive" value="200"/>
<property name="minIdle" value="5"/>
</bean>
<bean id="sqlSessionFactoryTest1" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSourceTest1" />
<property name="mapperLocations" value="classpath*:test/service/server/test1/**/*.xml" />
</bean>
<bean id="sqlSessionTest1" class="org.mybatis.spring.SqlSessionTemplate" name="sqlSessionTest1">
<constructor-arg name="sqlSessionFactory" ref="sqlSessionFactoryTest1" />
</bean>
<mybatis-spring:scan base-package="test.service.server.test1" template-ref="sqlSessionTest1" />
Oracle Account test2
<bean id="dataSourceTest2" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="net.sf.log4jdbc.DriverSpy"/>
<property name="url" value="jdbc:log4jdbc:oracle:thin:#222.222.2222.222:2222:Test2"/>
<property name="username" value="Test2"/>
<property name="password" value="Test2"/>
<property name="maxIdle" value="200"/>
<property name="maxActive" value="200"/>
<property name="minIdle" value="5"/>
</bean>
<bean id="sqlSessionFactoryTest2" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSourceTest2" />
<property name="mapperLocations" value="classpath*:test/service/server/test2/**/*.xml" />
</bean>
<bean id="sqlSessionTest2" class="org.mybatis.spring.SqlSessionTemplate" name="sqlSessionTest2">
<constructor-arg name="sqlSessionFactory" ref="sqlSessionFactoryTest2" />
</bean>
<mybatis-spring:scan base-package="test.service.server.test2" template-ref="sqlSessionTest2"/>
-----------------------root-context.xml END ---------------------------------------------------------
i am not used context:component-scan
<!-- <context:component-scan base-package="test.service.server.test1.test1service"/>-->
<!-- <context:component-scan base-package="test.service.server.test2.test2service"/>-->
I use the SpringJUnit4 each unit test
Were sequentially to (DataSourceTest and SqlSessionFactory Test and SqlSession Test mapperScanTest).
did not have any problems until mapperScanTest.
However, an error occurs when star using the annotation # Service
------------------------------------------service interface code ------------------------------------
public interface Test2_SERVICE {
public List<Test2_VO> GET_ListVO();
}
-------------------------------------------implement service code----------------------------------
#Service("Test2_SERVICE") *//<--Error annotaion*
public class Test2_SERVICEIMPLE implements Test2_SERVICE{
#Resource
Test2_MAPPER mapper;
#Override
public List<Test2_VO> GET_ListVO() {
return mapper.GET_ListMapperVO();
}
}
---------test Code------------------------------
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(locations = { "file:src/main/**/*-context.xml" })
public class TestService {
Logger logger = Logger.getLogger(Thread.currentThread().getClass());
#Autowired
#Qualifier("Test2_SERVICE")
Test2_SERVICE test2_SERVICE;
#Override
public void testString() {
logger.info("---------------------");
List<Test2_VO> listVO = test2_SERVICE.GET_ListVO();
logger.info(listVO );
logger.info("---------------------");
}
}
Error Messages-----------------------------------
Caused by:
org.springframework.context.annotation.ConflictingBeanDefinitionException:
Annotation-specified bean name 'Test2_SERVICE' for bean class
[test.service.server.test2.test2service.Test2_SERVICE] conflicts with
existing, non-compatible bean definition of same name and class
[test.service.server.test2.test2service.Test2_SERVICEIMPLE]
------------------------------------------------end---------------------------------------------
#Service("Test2_SERVICE") *//<--Error annotaion*
The problem did not exist until the object Test2_MAPPER
However, the error begins in Test2_SERVICE
# Service ("Test2_SERVICE") Where there is only used here (Test2_SERVICEIMPLE).
Because of this problem
I am suffering for three days..
Somebody tell me solve the problem for this error message.
Thank you for reading my article.
The problem is that you create a bean with the name "Test2_SERVICE" for Test2_SERVICEIMPLE with this annotation:
#Service("Test2_SERVICE")
//creates the bean with id="TEST2_Service" of the type Test2_SERVICEIMPLE
public class Test2_SERVICEIMPLE implements Test2_SERVICE
and then assign exactly this Test2_SERVICEIMPLE bean to the interface Test2Service
#Autowired
#Qualifier("Test2_SERVICE")
//here you assign the bean of the not matching type Test2_SERVICEIMPLE to
//a variable of type Test2_SERVICE
Test2_SERVICE test2_SERVICE;
That means that the interface wants to use the bean for the implementation...
So just remove/change the #Qualifier("Test2_SERVICE") or change the name of the #Service("Test2_SERVICE")
How to autowire annotation qualifiers and how to name autodetected components

How to create a SocketConfig class in Spring using factory-method?

I am using apache commons httpclient 4.3.x along with spring3. I am trying to wire up a connectionpool with it's associated socketconfig instance.
http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.html
http://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/config/SocketConfig.html?is-external=true
My code looks like this:
<bean id="socketConfig" class="org.apache.http.config.SocketConfig" factory-method="custom" init-method="build">
<property name="soTimeout" value="60000"/>
<property name="soLinger" value="5" />
</bean>
<bean name="poolingHttpConnectionManager" class="org.apache.http.impl.conn.PoolingHttpClientConnectionManager" depends-on="socketConfig">
<property name="maxTotal" value="20" />
<property name="defaultMaxPerRoute" value="20" />
<property name="defaultSocketConfig" ref="socketConfig" />
</bean>
However, this is not working. The instance type that is used to setDefaultSocketConfig() on PoolingHttpClientConnectionManager is of type SocketConfig.Builder instead of SocketConfig.
What I want to have happen is as follows:
SocketConfig config = SocketConfig.custom()
.setSoTimeout(60000)
.setSoLinger(5)
.build()
So, I expect that the socketConfig bean type should be a SocketConfig instance, not a SocketConfig.Builder instance.
As per spring docs, I thought this should work.
http://docs.spring.io/spring/docs/3.0.x/spring-framework-reference/htmlsingle/spring-framework-reference.html#beans-factory-class-static-factory-method
is there anything I am doing wrong? Or is this just not supported in spring?
It turns out that the socketconfig builder instance is not designed to work with spring very well.
I had to use a spring beanfactory implementation to create the instance.
The bean class:
import org.apache.http.config.SocketConfig;
import org.springframework.beans.factory.FactoryBean;
public class SocketConfigFactoryBean implements FactoryBean<SocketConfig> {
int soLinger;
int soTimeout;
public SocketConfig getObject() throws Exception {
return SocketConfig.custom()
.setSoLinger(soLinger)
.setSoTimeout(soTimeout)
.build();
}
public Class<?> getObjectType() {
return SocketConfig.class;
}
public boolean isSingleton() {
return true;
}
public int getSoLinger() {
return soLinger;
}
public void setSoLinger(int soLinger) {
this.soLinger = soLinger;
}
public int getSoTimeout() {
return soTimeout;
}
public void setSoTimeout(int soTimeout) {
this.soTimeout = soTimeout;
}
}
The bean definition
<bean name="poolingHttpConnectionManager" class="org.apache.http.impl.conn.PoolingHttpClientConnectionManager">
<property name="maxTotal" value="20" />
<property name="defaultMaxPerRoute" value="20" />
<property name="defaultSocketConfig">
<bean class="org.apache.http.config.SocketConfig" factory-method="custom" init-method="build">
<bean class="com.ex.spring.beans.factory.SocketConfigFactoryBean">
<property name="soTimeout" value="60000"/>
<property name="soLinger" value="5" />
</bean>
</property>
</bean>
I was able to achieve it by doing the next configuration in spring:
<bean id="socketConfig" class="org.apache.http.config.SocketConfig" factory-method="custom">
<property name="soTimeout" value="1000" />
<property name="soLinger" value="5" />
</bean>
<bean name="poolingHttpConnectionManager" class="org.apache.http.impl.conn.PoolingHttpClientConnectionManager">
<property name="maxTotal" value="20" />
<property name="defaultMaxPerRoute" value="20" />
<property name="defaultSocketConfig">
<bean factory-bean="socketConfig" factory-method="build" />
</property>
</bean>

Resources