標籤:
使用mybatis-3.2.2.jar + mybatis-spring-1.2.0.jar整合時,報以下異常:
15:42:48.538 [Thread-1] DEBUG o.s.b.f.s.DisposableBeanAdapter - Invoking destroy method ‘close‘ on bean with name ‘sqlSession‘15:42:48.586 [Thread-1] WARN o.s.b.f.s.DisposableBeanAdapter - Invocation of destroy method ‘close‘ failed on bean with name ‘sqlSession‘java.lang.UnsupportedOperationException: Manual close is not allowed over a Spring managed SqlSession at org.mybatis.spring.SqlSessionTemplate.close(SqlSessionTemplate.java:306) ~[mybatis-spring-1.2.0.jar:1.2.0] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_11] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_11] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_11] at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_11] at org.springframework.beans.factory.support.DisposableBeanAdapter.invokeCustomDestroyMethod(DisposableBeanAdapter.java:327) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE] at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:253) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:510) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:486) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:740) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:455) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE] at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1090) [spring-context-3.2.3.RELEASE.jar:3.2.3.RELEASE] at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1064) [spring-context-3.2.3.RELEASE.jar:3.2.3.RELEASE] at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:980) [spring-context-3.2.3.RELEASE.jar:3.2.3.RELEASE]15:42:48.586 [Thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retrieved dependent beans for bean ‘com.pinganfu.common.log.SQLLogInterceptor#1bbf683‘: [sqlSessionFactory]15:42:48.586 [Thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retrieved dependent beans for bean ‘com.pinganfu.common.pagination.MySql5Dialect#c8211c‘: [com.pinganfu.common.pagination.PaginationInterceptor#76c8cd]15:42:48.586 [Thread-1] DEBUG o.s.b.f.s.DisposableBeanAdapter - Invoking destroy method ‘close‘ on bean with name ‘dataSource‘
參考這裡
http://code.google.com/p/mybatis/issues/detail?id=778
SqlSessionTemplate你不可以手動關閉。SqlSessionTemplate是一個代理類,內部他會為每次請求建立安全執行緒的sqlsession,並與Spring進行整合.在你的方法調用完畢以後他會自動關閉的。
異常:java.lang.UnsupportedOperationException: Manual close is not allowed over a Spring managed SqlSession