title: In which cases should I use destroy-method of DataSource?
body: <p>I know destroy-method is used to ask spring to call a specific method to clean up. <a href="http://www.mkyong.com/spring/spring-init-method-and-destroy-method-example/" rel="nofollow">Source</a>. I am using Spring Transaction Manager in my code. I am wondering if using this attribute is useful. If yes, how can I use it? If not when is it useful?</p>
  
  <p>I know that Spring automatically call that method, but when should I use that? Which parts are not handled by Spring that I would need such method?</p>
  
  <p><strong>DataSource attribute</strong></p>
  
  <pre><code>&lt;bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource"
          destroy-method="close"&gt;
    ...
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;bean id="transactionManager"
      class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
      &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
  &lt;/bean&gt;
  
  &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;
  </code></pre>
  
  <p><strong>Service</strong> </p>
  
  <pre><code>@Service
  public MyServiceImpl implements MyService{
  
  @Transactional
  public void saveData(MyData data){
     ...
  }
  
  @Transactional(readOnly = true)
  public List&lt;MyData) readData(long id){
     ...
  }
  }
  </code></pre>
  
  <p><strong>Repository</strong></p>
  
  <pre><code>@Repository
  public MyReposImpl implements MyRepos{
  
  @Autowired
  SessionFactory sessionFactory;
  
  
  public void saveData(MyData data) throws HibernateException{
       sessionFactory.getCurrentSession().save(data);
  }
  
  
  public List&lt;MyData&gt; readData(long id) throws HibernateException{
     ...
  }
  </code></pre>