xml文件中的常见bug

BUG代码

一:

java.lang.Exception: DEBUG STACK TRACE for PoolBackedDataSource.close().  

    at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.close(AbstractPoolBackedDataSource.java:417)  
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
    ......  
java.lang.Exception: DEBUG -- CLOSE BY CLIENT STACK TRACE  
    at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:566)  
    at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:234)  
    .....  

主要原因就是Xml代码 添加了 destroy-method属性 
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">  
//略去数据源相关信息的配置  
</bean>  
Spring在读取这个配置文件以后,需要根据这些信息来实例化一些类,然后内部再根据中间的那些配置信息来实际构造数据源。

 可是来了个问题。不能保证这里的ComboPooledDataSource数据源一定是可用的,也不能保证close方法一定能关闭连接,

对吧?Spring本身不能检查这个类是否 真实有效,毫无Bug。实际上呢,也检查不了。同样的,close方法是否有效,

也需要进行检查所。以当不能确定destory-method的情况下,把该项删除,由程序自主选择关闭方法,这样Debug就不会报错了.

二:
2016-12-22 17:55:04,520 - WARN  [localhost-startStop-1] org.springframework.beans.factory.support.DisposableBeanAdapter  

- Invocation of destroy method 'close' failed on bean with name 'sqlSessionService'java.lang.UnsupportedOperationException: 

Manual close is not allowed over a Spring managed SqlSession 

    at org.mybatis.spring.SqlSessionTemplate.close(SqlSessionTemplate.java:310)    

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)    

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)    

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)    

    at java.lang.reflect.Method.invoke(Method.java:498)

解决方案:

<bean id="sqlSessionService" class="org.mybatis.spring.SqlSessionTemplate" scope="prototype">    

    <constructor-arg index="0" ref="sqlSessionFactoryService" />

</bean>

猜你喜欢

转载自blog.csdn.net/qq_42436644/article/details/85368221