官方网站介绍的关于BoneCP
在Spring 当中配置BoneCP
可以使用方式:Spring+LazyDataSource(目前使用的是这样的配置)
1
说一下依赖包
>google-collections-1.0.jar.
- 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(目前使用的是这样的配置)
1
说一下依赖包
>google-collections-1.0.jar.
>slf4j-api-1.6.1.jar
>slf4j-log4j12-1.6.1.jar
>bonecp-0.7.0.jar
2
配置文件编写
applicationContext.xml
init.properties
3
配置slf4j时候报错:
解决办法是slf4j的版本太低。更换最新的版本即可。
至此结束。
2
配置文件编写
applicationContext.xml
- <!-- Spring bean configuration. Tell Spring to bounce off BoneCP -->
- <bean id="dataSource"
- class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
- <property name="targetDataSource">
- <ref local="mainDataSource" />
- </property>
- </bean>
- <bean id="placeholderConfig"
- class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
- <property name="location">
- <value>classpath:init.properties</value>
- </property>
- </bean>
- <bean id="mainDataSource" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close" dependency-check="none">
- <property name="driverClass">
- <value>${datasource.driverClassName}</value>
- </property>
- <property name="jdbcUrl">
- <value>${datasource.url}</value>
- </property>
- <property name="username">
- <value>${datasource.username}</value>
- </property>
- <property name="password">
- <value>${datasource.password}</value>
- </property>
- <property name="idleConnectionTestPeriod">
- <value>${boneCP.idleConnectionTestPeriod}</value>
- </property>
- <property name="idleMaxAge">
- <value>${boneCP.idleMaxAge}</value>
- </property>
- <property name="maxConnectionsPerPartition">
- <value>${boneCP.maxConnectionsPerPartition}</value>
- </property>
- <property name="minConnectionsPerPartition">
- <value>${boneCP.minConnectionsPerPartition}</value>
- </property>
- <property name="partitionCount">
- <value>${boneCP.partitionCount}</value>
- </property>
- <property name="acquireIncrement">
- <value>${boneCP.acquireIncrement}</value>
- </property>
- <property name="statementsCacheSize">
- <value>${boneCP.statementsCacheSize}</value>
- </property>
- <property name="statementsCachedPerConnection">
- <value>${boneCP.statementsCachedPerConnection}</value>
- </property>
- <property name="releaseHelperThreads">
- <value>${boneCP.releaseHelperThreads}</value>
- </property>
- </bean>
init.properties
- datasource.type=oracle
- datasource.driverClassName=oracle.jdbc.driver.OracleDriver
- datasource.url=jdbc:oracle:thin:@127.0.0.1:1521:orcl
- datasource.username=scott
- datasource.password=tiger
- boneCP.idleConnectionTestPeriod=60
- boneCP.idleMaxAge=240
- boneCP.maxConnectionsPerPartition=30
- boneCP.minConnectionsPerPartition=10
- boneCP.partitionCount=3
- boneCP.acquireIncrement=5
- boneCP.statementsCacheSize=100
- boneCP.statementsCachedPerConnection=30
- boneCP.releaseHelperThreads=3
3
配置slf4j时候报错:
- Exception in thread "main" java.lang.IllegalAccessError: tried to access field
- org.slf4j.impl.StaticLoggerBinder.SINGLETON from class org.slf4j.LoggerFactory
- at org.slf4j.LoggerFactory.<clinit>(LoggerFactory.java:60)
解决办法是slf4j的版本太低。更换最新的版本即可。
至此结束。