title: Spring + MyBatis exception: Mapped Statements collection does not contain value for
body: <p>I got this exception when I executed this app:</p>
  
  <pre><code>public class MainApp {
  
      private static ApplicationContext context = null;
      static SqlSession session = null;
  
      public static void main(String[] args) throws IllegalArgumentException {
          try {
  
              context = new FileSystemXmlApplicationContext(
                                              "src/main/webapp/WEB-INF/applicationContext.xml");
              session = (SqlSession) context.getBean("sqlSession");
              OrderMapper orderMapper = session.getMapper(OrderMapper.class);
              int orderQuantity = orderMapper.getAllOrder().size();
              System.out.println("Order quantity: " + orderQuantity);
              session.commit();
              session.close();
          } catch (Throwable e) {
              e.printStackTrace();
          } 
      }
  }
  </code></pre>
  
  <p>Here is my OrderMapper interface:</p>
  
  <pre><code>public interface OrderMapper {
  
      public List&lt;Order&gt; getAllOrder();
  }
  </code></pre>
  
  <p>OrderMapper.xml</p>
  
  <pre><code>&lt;!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
   "http://mybatis.org/dtd/mybatis-3-mapper.dtd"&gt;
  
  &lt;mapper namespace="com.thonglm1.spring.mappers.OrderMapper"&gt;
  
      &lt;resultMap id="result" type="order"&gt;
          &lt;result property="orderId" column="cartid" /&gt;
          &lt;result property="type" column="type" /&gt;
          &lt;result property="saleId" column="saleId" /&gt;
          &lt;result property="status" column="status" /&gt;
          &lt;result property="info1" column="info1" /&gt;
          &lt;result property="info2" column="info2" /&gt;
          &lt;result property="info3" column="info3" /&gt;
      &lt;/resultMap&gt;
  
      &lt;select id="getAllOrder" resultMap="result"&gt;
          select cartId, type,
          info1
          from TRAIN_ORDER;
      &lt;/select&gt;
  &lt;/mapper&gt;
  </code></pre>
  
  <p>applicationContext.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
      xmlns:security="http://www.springframework.org/schema/security"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xsi:schemaLocation="
          http://www.springframework.org/schema/aop 
          http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
          http://www.springframework.org/schema/beans 
          http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
          http://www.springframework.org/schema/context 
          http://www.springframework.org/schema/context/spring-context-2.5.xsd
          http://www.springframework.org/schema/tx 
          http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
  
      &lt;bean id="dataSource"
          class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
          &lt;property name="driverClassName" value="oracle.jdbc.OracleDriver" /&gt;
          &lt;property name="url" value="jdbc:oracle:thin:@172.21.8.62:1521:SHESVDEV" /&gt;
          &lt;property name="username" value="test" /&gt;
          &lt;property name="password" value="test" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="configLocation" value="src/main/webapp/WEB-INF/mybatis-config.xml" /&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 class="org.mybatis.spring.mapper.MapperScannerConfigurer"&gt;
      &lt;property name="basePackage" value="com.thonglm1.spring.mappers" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="transactionManager"
          class="org.springframework.jdbc.datasource.DataSourceTransactionManager"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>mybatis-config.xml</p>
  
  <pre><code>?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE configuration
      PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
      "http://mybatis.org/dtd/mybatis-3-config.dtd"&gt;
  &lt;configuration&gt;
      &lt;typeAliases&gt;
          &lt;typeAlias type="com.thonglm1.spring.domain.Order" alias="order" /&gt;
      &lt;/typeAliases&gt;
      &lt;mappers&gt;
          &lt;package name="com.thonglm1.spring.mappers" /&gt;
      &lt;/mappers&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>And finally, the exception I got:</p>
  
  <blockquote>
    <p>java.lang.IllegalArgumentException: Mapped Statements collection does
    not contain value for
    com.thonglm1.spring.mappers.OrderMapper.getAllOrder   at
    org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:672)
      at
    org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:507)
      at
    org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:500)
      at
    org.apache.ibatis.binding.MapperMethod.setupCommandType(MapperMethod.java:240)
      at
    org.apache.ibatis.binding.MapperMethod.(MapperMethod.java:71)
      at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:39)
      at $Proxy6.getAllOrder(Unknown Source)  at
    MainApp.main(MainApp.java:21)</p>
  </blockquote>
  
  <p>And 1 more thing, since I quite new to this, is there any bad practices in my code ? Or anything I could improve ? Please feel free to comment, I'd really appreciate it.</p>