日期:2014-05-16 浏览次数:20452 次
大家且看ibatis2.1.7.597源码:
private BasicDataSource legacyDbcpConfiguration(Map map) { BasicDataSource basicDataSource = null; if (map.containsKey("JDBC.Driver")) { basicDataSource = new BasicDataSource(); String driver = (String) map.get("JDBC.Driver"); String url = (String) map.get("JDBC.ConnectionURL"); String username = (String) map.get("JDBC.Username"); String password = (String) map.get("JDBC.Password"); String validationQuery = (String) map.get("Pool.ValidationQuery"); String maxActive = (String) map.get("Pool.MaximumActiveConnections"); String maxIdle = (String) map.get("Pool.MaximumIdleConnections"); String maxWait = (String) map.get("Pool.MaximumWait"); basicDataSource.setUrl(url); basicDataSource.setDriverClassName(driver); basicDataSource.setUsername(username); basicDataSource.setPassword(password); if (notEmpty(validationQuery)) { basicDataSource.setValidationQuery(validationQuery); } if (notEmpty(maxActive)) { basicDataSource.setMaxActive(Integer.parseInt(maxActive)); } if (notEmpty(maxIdle)) { basicDataSource.setMaxIdle(Integer.parseInt(maxIdle)); } if (notEmpty(maxWait)) { basicDataSource.setMaxWait(Integer.parseInt(maxWait)); } } return basicDataSource; }
?这段代码的目的是读取ibatis中的sqlMapConfig.xml配置文件的,下面是这个配置文件的具体长像:
<transactionManager type="JDBC"> <dataSource type="DBCP"> <property name="JDBC.Driver" value="com.mysql.jdbc.Driver" /> <property name="JDBC.ConnectionURL" value="jdbc:mysql://xxx" /> <property name="JDBC.Username" value="root" /> <property name="JDBC.Password" value="xxx" /> <property name="Pool.MaximumActiveConnections" value="15"/> <property name="Pool.MaximumIdleConnections" value="15"/> <property name="Pool.MaximumWait" value="1000"/> <property name="Pool.RemoveAbandoned" value="true"/> <property name="Pool.RemoveAbandonedTimeout" value="1"/> <property name="asdfaf" value="1"/> </dataSource> </transactionManager>
?可以看到源代码里只有以下几项对dbcp的配置是可以在ibatis中配置的,其余都是用的dbcp的默认值:
????? String validationQuery = (String) map.get("Pool.ValidationQuery");
????? String maxActive = (String) map.get("Pool.MaximumActiveConnections");
????? String maxIdle = (String) map.get("Pool.MaximumIdleConnections");
????? String maxWait = (String) map.get("Pool.MaximumWait");
结论:不知道是否是我的遗漏,但是看了源代码确实是只对了这四个配置项进行了处理,其他的没有提到。实际影响到我的后果就是我对
<property name="Pool.RemoveAbandoned" value="true"/>?
<property name="Pool.RemoveAbandonedTimeout" value="1"/>?
这两项的配置由于ibatis的阻碍,dbcp实际上是看不到的,真不知道ibatis的这个版本是怎么回事,感觉没有完全用上DBCP,不知道接下来的版本会不会有所改进。