diff --git a/src/main/java/org/mybatis/spring/SqlSessionTemplate.java b/src/main/java/org/mybatis/spring/SqlSessionTemplate.java index eb418ae1a3..fb3378c381 100644 --- a/src/main/java/org/mybatis/spring/SqlSessionTemplate.java +++ b/src/main/java/org/mybatis/spring/SqlSessionTemplate.java @@ -37,6 +37,7 @@ import org.apache.ibatis.session.RowBounds; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; +import org.springframework.beans.factory.DisposableBean; import org.springframework.dao.support.PersistenceExceptionTranslator; /** @@ -69,12 +70,12 @@ * @author Putthibong Boonbong * @author Hunter Presnall * @author Eduardo Macarron - * + * * @see SqlSessionFactory * @see MyBatisExceptionTranslator * @version $Id$ */ -public class SqlSessionTemplate implements SqlSession { +public class SqlSessionTemplate implements SqlSession, DisposableBean { private final SqlSessionFactory sqlSessionFactory; @@ -395,6 +396,28 @@ public List flushStatements() { } /** + * Allow gently dispose bean: + *
+  * {@code
+  *
+  * 
+  *  
+  * 
+  * }
+  *
+ * + * The implementation of {@link DisposableBean} forces spring context to use {@link DisposableBean#destroy()} method instead of {@link SqlSessionTemplate#close()} to shutdown gently. + * + * @see SqlSessionTemplate#close() + * @see org.springframework.beans.factory.support.DisposableBeanAdapter#inferDestroyMethodIfNecessary + * @see org.springframework.beans.factory.support.DisposableBeanAdapter#CLOSE_METHOD_NAME + */ + @Override + public void destroy() throws Exception { + //This method forces spring disposer to avoid call of SqlSessionTemplate.close() which gives UnsupportedOperationException + } + + /** * Proxy needed to route MyBatis method calls to the proper SqlSession got * from Spring's Transaction Manager * It also unwraps exceptions thrown by {@code Method#invoke(Object, Object...)} to