JUnit测试时,Mybatis报错:Manual close is not allowed over a Spring managed SqlSessio

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/IRhythm/article/details/78316025

一、问题:JUnit测试时,mybatis报错:java.lang.UnsupportedOperationException: Manual close is not allowed over a Spring managed SqlSession;

二、解决方案:在Mybatis的配置文件中在配置SqlSessionTemplate的标签中添加一个属性:scope="prototype",如下:

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

猜你喜欢

转载自blog.csdn.net/IRhythm/article/details/78316025
今日推荐