title: Spring 3 : @Autowired dao fields are null in service beans with @Transactional annotation
body: <p>I code to interfaces as follows :</p>
  
  <p>DAO interface :</p>
  
  <pre><code>public interface SampleTblDao extends BaseDao&lt;SampleTbl&gt; {
  
  /**
  * 
  * @param mapper
  * @param sampleKey
  * @return
  * @throws DataAccessException
  */
  public SampleTbl selectSampleTbl(SampleKey sampleKey) throws DataAccessException;
  
  }
  </code></pre>
  
  <p>DAO implementation </p>
  
  <pre><code>public class SampleTblDaoImpl extends AbstractBaseDao&lt;SampleTbl, SampleTblMapper&gt; implements SampleTblDao {
  
    public SampleTblDaoImpl() {
      super(SampleTblMapper.class);
    }
  
    @Override
    public SampleTbl selectSampleTbl(SampleKey sampleKey) throws DataAccessException {
      return getSqlSession().getMapper(SampleTblMapper.class).selectSampleTbl(sampleKey);
    }
  
  }
  </code></pre>
  
  <p>Business-logic interface :</p>
  
  <pre><code>public interface SampleBusinessLogic {
  
    /**
     * 
     * @param sample
     * @return
     * @throws SampleException
     */
    public Sample createSample(Sample sample) throws SampleException;
  
    /**
     * 
     * @param sample
     * @return
     * @throws SampleException
     */
     public Sample updateSample(Sample sample) throws SampleException;
  
    /**
     * @param sampleKey
     * @return
     * @throws SampleException
     */
     public Sample getSample(SampleKey sampleKey) throws SampleException;
  
     }
  </code></pre>
  
  <p>Business-logic implementation :</p>
  
  <pre><code> public class SampleBusinessLogicImpl implements SampleBusinessLogic {
  
      /**
       * sample table dao
       */
      @Autowired
      @Qualifier(value = "sampleTblDao")
      private SampleTblDao sampleTblDao;
  
      @Override
      @Transactional(rollbackFor = Exception.class)
      public Sample createSample(Sample sample) throws SampleException {
  
          try {
              // sample table
              createSampleTbl(sample.getSampleTbl());
  
          } catch (Exception e) {
  
              List &lt; String &gt; messageList = new ArrayList &lt; String &gt; ();
              String message = "{createSample : " + "{itemId=" + sample.getSampleTbl().getItemId() + "}," + "{itemName=" + sample.getSampleTbl().getItemName() + "}}";
  
              messageList.add("createShop system error");
  
              throw new SampleException(message, messageList, e);
  
          }
  
          return sample;
      }
  
      @Override
      @Transactional(rollbackFor = Exception.class)
      public Sample updateSample(Sample sample) throws SampleException {
  
          List &lt; String &gt; messageList = null;
          String message = null;
  
          try {
  
              // global shop table
              updateSampleTbl(sample.getSampleTbl());
  
          } catch (IllegalDataException e) {
  
              message = "{updateSample : " + "{itemId=" + sample.getSampleTbl().getItemId() + "}," + "{itemName=" + sample.getSampleTbl().getItemName() + "}}";
  
              messageList = new ArrayList &lt; String &gt; ();
              messageList.add("updateSample illegal data error");
  
              throw new SampleException(message, messageList, e);
  
          } catch (Exception e) {
  
              message = "{updateSample : " + "{itemId=" + sample.getSampleTbl().getItemId() + "}," + "{itemName=" + sample.getSampleTbl().getItemName() + "}}";
  
              messageList = new ArrayList &lt; String &gt; ();
              messageList.add("updateSample system error");
  
              throw new SampleException(message, messageList, e);
  
          }
  
          return sample;
  
      }
  
      @Override
      @Transactional(rollbackFor = Exception.class, readOnly = true)
      public Sample getSample(SampleKey sampleKey) throws SampleException {
  
          Sample sample = new Sample();
  
          String message = null;
          List &lt; String &gt; messageList = null;
  
          try {
  
              sample.setSampleTbl(getSampleTbl(sampleKey));
  
          } catch (DataNotFoundException e) {
  
              message = "{getSample : " + "{itemId=" + sampleKey.getItemId() + "}}";
  
              messageList = new ArrayList &lt; String &gt; ();
              messageList.add("getSample data not found error");
  
              throw new SampleException(message, messageList, e);
  
          } catch (Exception e) {
  
              message = "{getSample : " + "{itemId=" + sampleKey.getItemId() + "}}";
  
              messageList = new ArrayList &lt; String &gt; ();
              messageList.add("getSample system error");
  
              throw new SampleException(message, messageList, e);
  
          }
  
          return sample;
      }
  
      /**
       *
       * @param sampleTbl
       * @throws Exception
       */
      private void createSampleTbl(SampleTbl sampleTbl) throws Exception {
  
          sampleTbl.setItemId(new UUID().toString());
          sampleTblDao.insert(sampleTbl);
      }
  
      /**
       * @param sampleTbl
       * @throws Exception
       */
      private void updateSampleTbl(SampleTbl sampleTbl) throws Exception {
  
          if (sampleTbl.isTransactionTarget(SampleTbl.class)) {
  
              String message = null;
              SampleKey sampleKey = new SampleKey();
              sampleKey.setItemId(sampleTbl.getItemId());
  
              SampleTbl sampleTblPre = sampleTblDao.selectSampleTbl(sampleKey);
  
              if (sampleTblPre == null) {
                  // if sample table is empty
                  message = "{illegal data error:{sampleTblPre=null}}";
                  throw new IllegalDataException(message);
              }
  
              sampleTbl.setItemId(sampleTblPre.getItemId());
              sampleTblDao.update(sampleTbl);
  
          }
  
      }
  
      /**
       * @param sampleKey
       * @return
       * @throws Exception
       */
      private SampleTbl getSampleTbl(SampleKey sampleKey) throws Exception {
  
          String message = "";
  
          SampleTbl sampleTbl = sampleTblDao.selectSampleTbl(sampleKey);
  
          if (sampleTbl == null) {
              // if sample tbl is empty
              message = "{data not found error:{SampleTbl=null}}";
              throw new DataNotFoundException(message);
          }
  
          return sampleTbl;
      }
  
      public void setSampleTblDao(SampleTblDao sampleTblDao) {
          this.sampleTblDao = sampleTblDao;
      }
  }
  </code></pre>
  
  <p>In the application context XML I have configured beans as follows :</p>
  
  <pre><code>&lt;bean id="sampleTblDao" class="com.rakuten.gep.sample.dao.impl.SampleTblDaoImpl" parent="baseDAO" scope="singleton"&gt;
          &lt;property name="namespace" value="com.rakuten.gep.sample.dao.mapper.SampleTblMapper" /&gt;
  &lt;/bean&gt;
  &lt;bean id="sampleBusinessLogic" class="com.rakuten.gep.sample.businesslogic.impl.SampleBusinessLogicImpl" scope="singleton"/&gt;
  
  &lt;!-- and annocation based transaction is configured as follows --&gt;
  &lt;tx:annotation-driven transaction-manager="trx-manager" proxy-target-class="true" /&gt;
  
  &lt;bean id="trx-manager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"&gt;
         &lt;property name="dataSource" ref="dataSource"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>But after debugging, I realized that in the autowired field 'sampleTblDao' in 'SampleBusinessLogicImpl' is always null.</p>
  
  <p>Any tips?</p>