mardi 17 mars 2015

How to configure multiple datasource in spring

in my application i am trying to configure two database. After configured my application get deployed and successfully running with first database, but when ever i am try to access the second database i am getting "" this exception. Could any one help me... Thanks in advance.


My Configuration.xml file



<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:database.properties"></property>



<bean id="dataSource" class="com.iii.orn11j.common.dao.OrionDataSource"
destroy-method="close" >

<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="${database.url}"></property>
<property name="username" value="${database.username}"></property>
<property name="password" value="${database.password}"></property>

<property name="removeAbandoned" value="true" />
<property name="removeAbandonedTimeout" value="60" />
<property name="logAbandoned" value="false" />

<property name="initialSize" value="2" />
<property name="maxWait" value="30000" />
<property name="maxActive" value="30" />
<property name="minIdle" value="5" />
<property name="maxIdle" value="15" />

<!-- <property name="validationQuery" value="select 1 from dual" />
<property name="testOnBorrow" value="true" />
<property name="testWhileIdle" value="true" /> -->
</bean>

<bean id="dataSource2" class="com.iii.orn11j.common.dao.OrionDataSource"
destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="${database.url2}"></property>
<property name="username" value="${database.username2}"></property>
<property name="password" value="${database.password2}"></property>

<property name="removeAbandoned" value="true" />
<property name="removeAbandonedTimeout" value="60" />
<property name="logAbandoned" value="false" />

<property name="initialSize" value="2" />
<property name="maxWait" value="30000" />
<property name="maxActive" value="30" />
<property name="minIdle" value="5" />
<property name="maxIdle" value="15" />
</bean>

<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>


And my Query method is:



@Autowired
OrionDataSource dataSource2;
@Override
public void testCon()throws Exception{
JdbcTemplate temp=new JdbcTemplate(dataSource2);
String qry="SELECT COUNT(*) FROM OM_ITEM";
Integer count=(Integer)temp.queryForObject(qry, Integer.class);
System.out.println("Connected 2nd DB -----> "+count);
}

Aucun commentaire:

Enregistrer un commentaire