title: How to configure 2 databases in MyBatis using MyBatis-Spring
body: <p>I am trying to configure 2 different datasources in my application as it is required. </p>
  
  <p>My configuration in the AppContext.xml is as follows:</p>
  
  <pre><code>&lt;bean id="dataSourceA" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;  
       &lt;property name="driverClassName" value="com.ibm.db2.jcc.DB2Driver"/&gt;  
       &lt;property name="url" value="datasourceAURL"/&gt;  
       &lt;property name="username" value="aaaa"/&gt;  
       &lt;property name="password" value="pppp"/&gt;    
  &lt;/bean&gt;
        &lt;bean id="dataSourceB" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;  
       &lt;property name="driverClassName" value="com.ibm.db2.jcc.DB2Driver"/&gt;  
       &lt;property name="url" value="datasourceBURL"/&gt;  
       &lt;property name="username" value="bbbb"/&gt;  
       &lt;property name="password" value="cccc"/&gt;    
  &lt;/bean&gt;
  
  &lt;bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"&gt;  
             &lt;property name="basePackage" value="com/ex/myBatis/mappings" /&gt;  
        &lt;/bean&gt; 
  
        &lt;bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"&gt;  
       &lt;property name="dataSource" ref="dataSourceA" /&gt;  
       &lt;property name="typeAliasesPackage" value="com.ex.myBatis.entities"/&gt;  
  &lt;/bean&gt;
        &lt;bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate"&gt;  
       &lt;constructor-arg index="0" ref="sqlSessionFactory" /&gt;  
        &lt;/bean&gt;
  
        &lt;bean id="sqlSessionFactory1" class="org.mybatis.spring.SqlSessionFactoryBean"&gt;  
       &lt;property name="dataSource" ref="configDataSource" /&gt;  
       &lt;property name="typeAliasesPackage" value="com.ex.myBatis.entities"/&gt;  
        &lt;/bean&gt;
  
       &lt;bean id="sqlSession1" class="org.mybatis.spring.SqlSessionTemplate"&gt;  
      &lt;constructor-arg index="0" ref="sqlSessionFactory1" /&gt;  
       &lt;/bean&gt;
  
       &lt;bean id="callService" class="com.ex.myBatis.Service.callService"&gt;
      &lt;property name="sqlSession" ref="sqlSession1" /&gt;
       &lt;/bean&gt; 
  </code></pre>
  
  <p>But while accessing the bean I am getting the below Exception</p>
  
  <blockquote>
    <p>org.springframework.beans.factory.BeanCreationException: Error
    creating bean with name 'callService': Injection of autowired
    dependencies failed; nested exception is
    org.springframework.beans.factory.BeanCreationException: Could not
    autowire method: public final void
    org.mybatis.spring.support.SqlSessionDaoSupport.setSqlSessionTemplate(org.mybatis.spring.SqlSessionTemplate);
    nested exception is
    org.springframework.beans.factory.NoUniqueBeanDefinitionException: No
    qualifying bean of type [org.mybatis.spring.SqlSessionTemplate] is
    defined: expected single matching bean but found 2:
    sqlSession,sqlSession1</p>
  </blockquote>
  
  <p>Please somebody help me in figuring out the issue.
  Also please suggest me if there is someother way to configure 2 Datasources.</p>