Spring with MyBatis: expected single matching bean but found 2
<p>I've been using Spring with MyBatis and it's been working really well for a single database. I ran into difficulties when trying to add another database (see <a href="https://github.com/alexwoolford/mybatis-spring-multiple-mysql-reproducible-example" rel="noreferrer" title="reproducible example on Github">reproducible example on Github</a>).</p>

<p>I'm using Spring Java configuration (i.e. not XML). Most of the examples I've seen show how to achieve this using XML.</p>

<p>I have two data configuration classes (A &amp; B) like this:</p>

<pre><code>@Configuration
@MapperScan("io.woolford.database.mapper")
public class DataConfigDatabaseA {

    @Bean(name="dataSourceA")
    public DataSource dataSourceA() throws SQLException {
        SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
        dataSource.setDriver(new com.mysql.jdbc.Driver());
        dataSource.setUrl("jdbc:mysql://" + dbHostA + "/" + dbDatabaseA);
        dataSource.setUsername(dbUserA);
        dataSource.setPassword(dbPasswordA);
        return dataSource;
    }

    @Bean
    public SqlSessionFactory sqlSessionFactory() throws Exception {
        SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
        sessionFactory.setDataSource(dataSourceA());
        return sessionFactory.getObject();
    }
}
</code></pre>

<p>Two mappers, and a service that autowires the mappers:</p>

<pre><code>@Service
public class DbService {

    @Autowired
    private DbMapperA dbMapperA;

    @Autowired
    private DbMapperB dbMapperB;

    public List&lt;Record&gt; getDabaseARecords(){
        return dbMapperA.getDatabaseARecords();
    }

    public List&lt;Record&gt; getDabaseBRecords(){
        return dbMapperB.getDatabaseBRecords();
    }

}
</code></pre>

<p>The application won't start:</p>

<pre><code>Error creating bean with name 'dataSourceInitializer': 
  Invocation of init method failed; nested exception is 
    org.springframework.beans.factory.NoUniqueBeanDefinitionException: 
      No qualifying bean of type [javax.sql.DataSource] is defined: 
        expected single matching bean but found 2: dataSourceB,dataSourceA
</code></pre>

<p>I've read that it's possible to use the <code>@Qualifier</code> annotation to disambiguate the autowiring, though I wasn't sure where to add it.</p>

<p>Can you see where I'm going wrong?</p>