title: How to fix 'ibatis binding exception' when testing mybatis functionality in Springboot?
body: <p>I'm trying to make a unit test for Mybatis in SpringBoot. I keep getting ibatis.binding.bindingException whenever I try to execute a query defined in the mapper.xml.</p>
  
  <p>My test code is stored in src/test/java/service with name UserServiceImplTest. </p>
  
  <pre><code>@SpringBootTest
  @RunWith(SpringRunner.class)
  public class UserServiceImplTest {
  
  
      @Autowired
      UserDao userDao;
  
      @Test
      public void getUserByIdAndEmail() throws SQLException {
          User user = userDao.getUserByIdAndEmail("admin", "admin@sample.com");
          assertThat(user.getUser_email()).isEqualTo("admin@sample.com");
      }
  }
  </code></pre>
  
  <pre><code>@Repository
  public class UserDao implements UserDaoMapper{  
      @Autowired  
      private SqlSessionTemplate sqlSession;
  
      public User getUserByIdAndEmail(String user_id, String user_email) {
          UserDaoMapper mapper = sqlSession.getMapper(UserDaoMapper.class);
          return mapper.getUserByIdAndEmail(user_id, user_email);
      }   
  }
  </code></pre>
  
  <p>SqlSessionTemplate, SqlSessionFactory and Datasource beans are defined in a java file where there is @SpringBootApplication.</p>
  
  <p>From </p>
  
  <pre><code>User user = userDao.getUserByIdAndEmail("admin", "admin@sample.com");
  </code></pre>
  
  <p>I was hoping at least to get null User, but when executing the method itself the error pops out. Below is the error log.</p>
  
  <pre><code>org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.sampleProject.dao.UserDaoMapper.getUserByIdAndEmail
  
      at org.apache.ibatis.binding.MapperMethod$SqlCommand.&lt;init&gt;(MapperMethod.java:227)
      at org.apache.ibatis.binding.MapperMethod.&lt;init&gt;(MapperMethod.java:49)
      at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:65)
      at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58)
      at com.sun.proxy.$Proxy99.getUserByIdAndEmail(Unknown Source)
      at com.sampleProject.dao.UserDao.getUserByIdAndEmail(UserDao.java:25)
      at com.sampleProject.dao.UserDao$$FastClassBySpringCGLIB$$a267b137.invoke(&lt;generated&gt;)
      at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
      at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
      at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
      at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
      at com.sampleProject.dao.UserDao$$EnhancerBySpringCGLIB$$b41323d1.getUserByIdAndEmail(&lt;generated&gt;)
      at com.sampleProject.service.UserServiceImplTest.getUserByIdAndEmail(UserServiceImplTest.java:75)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74)
      at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84)
      at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
      at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
      at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
      at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
      at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
      at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
      at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
      at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
      at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
  </code></pre>