1. 程式人生 > >異常處理Manual close is not allowed over a Spring managed SqlSession

異常處理Manual close is not allowed over a Spring managed SqlSession

在SpringMVC 配合Mybatis的使用中出現這樣一個警告

[org.springframework.beans.factory.support.DisposableBeanAdapter (line-337)] - Invocation of destroy method ‘close’ failed on bean with name ‘sqlSession’: java.lang.UnsupportedOperationException: Manual close is not allowed over a Spring managed SqlSession

解決辦法:在Spring MVC的配置檔案中加入

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

重點是加上scope