BoneCP使用配置

官方网站介绍的关于BoneCP 
Java代码  收藏代码
  1. BoneCP is a fast, free, open-source, Java database connection pool (JDBC Pool) library. If you are familiar with C3P0 and DBCP then you already know what this means. For the rest, this is a library that will manage a database connection for you to get faster database access in your application.  

在Spring 当中配置BoneCP 
可以使用方式:Spring+LazyDataSource(目前使用的是这样的配置) 


说一下依赖包 
>google-collections-1.0.jar.
>slf4j-api-1.6.1.jar
>slf4j-log4j12-1.6.1.jar 
>bonecp-0.7.0.jar

配置文件编写 
applicationContext.xml 
Xml代码  收藏代码
  1. <!-- Spring bean configuration. Tell Spring to bounce off BoneCP -->  
  2.     <bean id="dataSource"  
  3.         class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">  
  4.         <property name="targetDataSource">  
  5.             <ref local="mainDataSource" />  
  6.         </property>  
  7.     </bean>  
  8.     <bean id="placeholderConfig"  
  9.         class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
  10.         <property name="location">  
  11.             <value>classpath:init.properties</value>  
  12.         </property>  
  13.     </bean>  
  14.     <bean id="mainDataSource" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close" dependency-check="none">  
  15.         <property name="driverClass">  
  16.             <value>${datasource.driverClassName}</value>  
  17.         </property>  
  18.         <property name="jdbcUrl">  
  19.             <value>${datasource.url}</value>  
  20.         </property>  
  21.         <property name="username">  
  22.             <value>${datasource.username}</value>  
  23.         </property>  
  24.         <property name="password">  
  25.             <value>${datasource.password}</value>  
  26.         </property>  
  27.    
  28.         <property name="idleConnectionTestPeriod">  
  29.             <value>${boneCP.idleConnectionTestPeriod}</value>  
  30.         </property>  
  31.    
  32.         <property name="idleMaxAge">  
  33.             <value>${boneCP.idleMaxAge}</value>  
  34.         </property>  
  35.         <property name="maxConnectionsPerPartition">  
  36.             <value>${boneCP.maxConnectionsPerPartition}</value>  
  37.         </property>  
  38.         <property name="minConnectionsPerPartition">  
  39.             <value>${boneCP.minConnectionsPerPartition}</value>  
  40.         </property>  
  41.         <property name="partitionCount">  
  42.             <value>${boneCP.partitionCount}</value>  
  43.         </property>  
  44.         <property name="acquireIncrement">  
  45.             <value>${boneCP.acquireIncrement}</value>  
  46.         </property>  
  47.         <property name="statementsCacheSize">  
  48.             <value>${boneCP.statementsCacheSize}</value>  
  49.         </property>  
  50.         <property name="statementsCachedPerConnection">  
  51.             <value>${boneCP.statementsCachedPerConnection}</value>  
  52.         </property>  
  53.         <property name="releaseHelperThreads">  
  54.             <value>${boneCP.releaseHelperThreads}</value>  
  55.         </property>  
  56.     </bean>  

init.properties 
Java代码  收藏代码
  1. datasource.type=oracle  
  2. datasource.driverClassName=oracle.jdbc.driver.OracleDriver  
  3. datasource.url=jdbc:oracle:thin:@127.0.0.1:1521:orcl  
  4. datasource.username=scott  
  5. datasource.password=tiger  
  6.    
  7.    
  8. boneCP.idleConnectionTestPeriod=60  
  9. boneCP.idleMaxAge=240     
  10. boneCP.maxConnectionsPerPartition=30  
  11. boneCP.minConnectionsPerPartition=10  
  12. boneCP.partitionCount=3  
  13.    
  14. boneCP.acquireIncrement=5                             
  15. boneCP.statementsCacheSize=100  
  16. boneCP.statementsCachedPerConnection=30  
  17. boneCP.releaseHelperThreads=3  


配置slf4j时候报错: 
Java代码  收藏代码
  1. Exception in thread "main" java.lang.IllegalAccessError: tried to access field  
  2. org.slf4j.impl.StaticLoggerBinder.SINGLETON from class org.slf4j.LoggerFactory  
  3.    at org.slf4j.LoggerFactory.<clinit>(LoggerFactory.java:60)  

解决办法是slf4j的版本太低。更换最新的版本即可。 
至此结束。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值