title: Why must the interface and xml mapper file be in same package and have the same name?
body: <p>Today I was preparing an example using Spring Boot and using MyBatis for the data access communication next to Spring-MyBatis. Here is the relevant project configuration (using maven):</p>
  
  <pre><code>src/main/java
  - edu.home.ltmj.controller
    + CategoryController.java
  - edu.home.ltmj.dao
    + CategoryDao.java
  - edu.home.ltmj.domain
    + Category.java
  src/main/resources
  - edu.home.ltmj.dao
    + CategoryMapper.xml
  </code></pre>
  
  <p>Relevant content of the files:</p>
  
  <p>CategoryDao.java:</p>
  
  <pre><code>package edu.home.ltmj.dao;
  
  public interface CategoryDao {
      List&lt;Category&gt; getAllCategories();
  }
  </code></pre>
  
  <p>CategoryMapper.xml:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;mapper namespace="edu.home.ltmj.dao.CategoryDao"&gt;
      &lt;resultMap id="categoryMap"
          type="edu.home.ltmj.domain.Category"&gt;
          &lt;id property="id" column="id" /&gt;
          &lt;result property="name" column="name" /&gt;
      &lt;/resultMap&gt;
      &lt;select id="getAllCategories" resultMap="categoryMap"&gt;
          SELECT id, nombre
          FROM category
      &lt;/select&gt;
  &lt;/mapper&gt;
  </code></pre>
  
  <p>Then, I inject an instance of this dao in a request controller (for testing purposes), like this:</p>
  
  <pre><code>package edu.home.ltmj.controller;
  
  @RestController
  public class CategoryController {
      @Autowired
      private CategoryDao dao;
  
      @RequestMapping(value="/category/all",
          method=RequestMethod.GET,
          produces=MediaType.APPLICATION_JSON_VALUE)
      public List&lt;Categoria&gt; getAllCategories() {
          return dao.getAllCategories();
      }
  }
  </code></pre>
  
  <p>I run my project and test the execution by using <code>curl localhost:8080/category/all</code> and then expected to see the results in JSON format, but I got this exception instead:</p>
  
  <pre><code>org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): edu.home.ltmj.dao.CategoryDao.getAllCategories
  at org.apache.ibatis.binding.MapperMethod$SqlCommand.&lt;init&gt;(MapperMethod.java:189)
  at org.apache.ibatis.binding.MapperMethod.&lt;init&gt;(MapperMethod.java:43)
  at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:58)
  at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:51)
  at com.sun.proxy.$Proxy45.getAllCategories(Unknown Source)
  at edu.home.ltmj.controller.CategoryRestController.getAllCategories(CategoryRestController.java:27)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  (...)
  </code></pre>
  
  <p>I don't understand the cause of this. There's an interface <code>CategoryDao</code> and it has the proper method <code>getAllCategories</code> that matches with <code>&lt;select id="getAllCategories"&gt;</code>. After some time of playing with this, I've changed the name of the dao interface to <code>CategoryMapper</code> and updated the namespace in CategoryMapper.xml. After I did this, <strong>everything worked normally</strong>. Also, after having the same name for class and xml, I moved the dao class and the xml mapper into different packages (stil using the same name for both: CategoryMapper.), updated the namespace in the xml file, and got the same exception, with the message updated to show the name of the package of the dao interface. But then again, I moved both files to the same package and everything worked again.</p>
  
  <p>So, my question is: <strong>why does MyBatis need that the interface and the xml mapper file to have the same name and be in the same package?</strong> Is this MyBatis design or an issue in Spring MyBatis?</p>