java - Manual close is not allowed over a Spring managed SqlSession
怪我咯
怪我咯 2017-04-17 17:52:37
0
1
1271

idea junit运行报错:java.lang.UnsupportedOperationException: Manual close is not allowed over a Spring managed SqlSession

<bean id="ks_dataSource" class="org.apache.commons.dbcp.BasicDataSource" 
destroy-method="close">

<bean id="ksSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="ks_dataSource"/>
    <property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml"/>
</bean>

<!-- 配置SqlSessionTemplate模板,注入相关配置 -->
<bean id="ksSqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
    <constructor-arg index="0" ref="ksSqlSessionFactory"/>
</bean>

<bean id="ksMapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage"
              value="com.elin4it.ssm.mapper.dao"/>
    <!-- 注意注入sqlSessionTemplate -->
    <property name="sqlSessionTemplateBeanName" value="ksSqlSessionTemplate"/>
</bean>
<!-- 添加ks数据库的commit事务管理 -->
<bean id="ksTransactionManager"
      class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="ks_dataSource"/>
</bean>

<!-- 开启事务控制的注解支持 -->
<tx:annotation-driven transaction-manager="ksTransactionManager"/>

报错具体:

10:42:15.178 [Thread-0] WARN  o.s.b.f.s.DisposableBeanAdapter - Invocation of destroy method 'close' failed on bean with name 'ksexptSqlSessionTemplate'
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.7.0_79]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_79]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_79]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_79]
at org.springframework.beans.factory.support.DisposableBeanAdapter.invokeCustomDestroyMethod(DisposableBeanAdapter.java:327) [spring-beans-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:253) [spring-beans-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:510) [spring-beans-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:486) [spring-beans-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:740) [spring-beans-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:455) [spring-beans-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1090) [spring-context-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1064) [spring-context-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:980) [spring-context-3.2.2.RELEASE.jar:3.2.2.RELEASE]
10:42:15.179 [Thread-0] DEBUG o.s.b.f.s.DisposableBeanAdapter - Invoking destroy method 'close' on bean with name 'ksexpt_dataSource'

Process finished with exit code 0

我试过配置SqlSessionTemplate为:

<bean id="ksSqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate" scope="prototype">
    <constructor-arg index="0" ref="ksSqlSessionFactory"/>
</bean>

以及直接注释掉SqlSessionTemplate,但是运行结果都没有变化

希望你们能够帮帮我= ^ = 谢谢!

怪我咯
怪我咯

走同样的路,发现不同的人生

Antworte allen(1)
刘奇

项目创建的问题,在module里面创建的

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage