title: @autowired and null ref exception
body: <p>//Located in com\src\myproject\services</p>
  
  <pre><code>package com.src.myproject.services;
  
  public interface IMyService {
      public boolean Method1();
  
  }
  </code></pre>
  
  <p>//Located in com\src\myproject\services</p>
  
  <pre><code>package com.src.myproject.services;
  
  public class MyService implements IMyService {
  
  
      @Autowired
      private TestMapper testMapper;
  
      @Override
      public boolean Method1() {
  
  
          return gettestMapper().GetOrder(1); //Get null pointer exception as testMapper is null in debug mode
      }
  
  
  
      public TestMapper gettestMapper(){
  
              return testMapper;
          }
  
  
      public void settestMapper(TestMapper testMapper){
          this.testMapper=testMapper;
          }
  
  }
  </code></pre>
  
  <p>My <code>mapper.java</code> files are located under <code>com\src\mappers</code></p>
  
  <p>and corresponding <code>mapper.xml</code> is located under <code>src\main\resources\com\src\myproject\mappers</code></p>
  
  <p>My <code>servelet-context.xml</code> file is</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
  xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
  xmlns:util="http://www.springframework.org/schema/util"
  xsi:schemaLocation="http://www.springframework.org/schema/beans 
                      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
                      http://www.springframework.org/schema/tx 
                      http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 
                      http://www.springframework.org/schema/context 
                      http://www.springframework.org/schema/context/spring-context-3.0.xsd
                      http://www.springframework.org/schema/util
                      http://www.springframework.org/schema/util/spring-util-3.1.xsd"&gt;
  
  
      &lt;!-- Root Context: defines shared resources visible to all other web components --&gt;
  
      &lt;context:property-placeholder location="/WEB-INF/spring/jdbc.properties,/WEB-INF/spring/mybatis.properties" /&gt;
  
      &lt;context:component-scan base-package="com.src.myproject.controllers" /&gt;
      &lt;context:component-scan base-package="com.src.myproject.services" /&gt;
  
  
      &lt;!-- Enable annotation style of managing transactions --&gt;
      &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;
  
      &lt;!-- Declare a datasource that has pooling capabilities --&gt;
      &lt;bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
      destroy-method="close" p:driverClass="${app.jdbc.driverClassName}"
      p:jdbcUrl="${app.jdbc.url}" p:user="${app.jdbc.username}" p:password="${app.jdbc.password}"
      p:acquireIncrement="10" p:idleConnectionTestPeriod="60" p:maxPoolSize="100"
      p:maxStatements="50" p:minPoolSize="10" /&gt;
  
      &lt;!-- Declare a transaction manager --&gt;
      &lt;bean id="transactionManager"
      class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
      p:dataSource-ref="dataSource"
      autowire="byName" /&gt;
  
  
      &lt;!-- define the SqlSessionFactory, notice that configLocation is not needed when you use MapperFactoryBean --&gt;
      &lt;bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="typeAliasesPackage" value="${typeAliasesPackage}" /&gt;
      &lt;/bean&gt;
  
      &lt;!-- scan for mappers and let them be autowired --&gt;
      &lt;bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"&gt;
          &lt;property name="basePackage" value="com.src.myproject.mappers" /&gt;
           &lt;property name="sqlSessionFactory" ref="sqlSessionFactory" /&gt;
      &lt;/bean&gt; 
  &lt;/beans&gt;
  </code></pre>
  
  <p>The autowiring in the services files is always null and gives null ref exception when I try to use any method from the mapper files via auto wire.</p>