title: Adding mapper to myBatis configuration in Java
body: <p>I want to migrate from XML configuration to Java configuration.</p>
  
  <pre><code>sqlSessionFactory.getConfiguration().setEnvironment(new Environment("development", new org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory(), getDataSouroce()));
  </code></pre>
  
  <p>I managed to replace all <code>&lt;environments&gt;</code> section with Java configuration (I have removed <code>&lt;environments&gt;</code> from XML configuration file), but I can't get rid of:</p>
  
  <pre><code> &lt;mappers&gt;&lt;mapper resource="mailbox/db/map/FileMapper.xml"/&gt; &lt;/mappers&gt;
  </code></pre>
  
  <p>I tried to write:</p>
  
  <blockquote>
    <p>sqlSessionFactory.getConfiguration().addMapper(FileMapper.class);</p>
  </blockquote>
  
  <p>but there are exceptions:</p>
  
  <pre><code>SqlSession sqlSession = MyBatisConnectionFactory.instance.getSqlSessionFactory().openSession();
  
      FileExample fe = new FileExample();
      Criteria f = fe.createCriteria().andIdBetween(0L, 5L);
      FileMapper mapper = (FileMapper) sqlSession.getMapper(FileMapper.class);
      List&lt;File&gt; allRecords = mapper.selectByExample(fe);
  
  // Mapped Statements collection does not contain value for mailbox.db.dao.FileMapper.selectByExample
  </code></pre>