HikariCP: http://brettwooldridge.github.io/HikariCP/
spring配置文件里,配置HikariCP数据库连接池
<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
<property name="driverClassName" value="${db.driverClassName}" />
<property name="jdbcUrl" value="${db.url}" />
<property name="username" value="${db.username}" />
<property name="password" value="${db.password}" />
<property name="connectionTimeout" value="${db.connectionTimeout}" />
<property name="readOnly" value="${db.readOnly}" />
<property name="maxLifetime" value="${db.maxLifetime}" />
<property name="maximumPoolSize" value="${db.maximumPoolSize}" />
<property name="idleTimeout" value="${db.idleTimeout}" />
<property name="poolName" value="${db.poolName}" />
<property name="connectionTestQuery" value="${db.connectionTestQuery}" />
<property name="dataSourceProperties">
<props>
<prop key="cachePrepStmts">${db.cachePrepStmts}</prop>
<prop key="prepStmtCacheSize">${db.prepStmtCacheSize}</prop>
<prop key="prepStmtCacheSqlLimit">${db.prepStmtCacheSqlLimit}</prop>
<prop key="useServerPrepStmts">${db.useServerPrepStmts}</prop>
<prop key="useLocalSessionState">${db.useLocalSessionState}</prop>
<prop key="useLocalTransactionState">${db.useLocalTransactionState}</prop>
<prop key="rewriteBatchedStatements">${db.rewriteBatchedStatements}</prop>
<prop key="cacheResultSetMetadata">${db.cacheResultSetMetadata}</prop>
<prop key="cacheServerConfiguration">${db.cacheServerConfiguration}</prop>
<prop key="elideSetAutoCommits">${db.elideSetAutoCommits}</prop>
<prop key="maintainTimeStats">${db.maintainTimeStats}</prop>
</props>
</property>
</bean>
<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
<constructor-arg ref="hikariConfig" />
</bean>
HikariCP配置数据库信息
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:hibernate.properties</value>
</list>
</property>
</bean>
各个软件版本:
Obs.: the versions are
log4j: 1.2.16
springframework: 3.1.4.RELEASE
HikariCP: 1.4.0
数据库配置文件
Properties file (hibernate.properties):
hibernate.dataSourceClassName=oracle.jdbc.pool.OracleDataSource
hibernate.hikari.maximumPoolSize=10
hibernate.hikari.idleTimeout=30000
dataSource.url=jdbc:oracle:thin:@localhost:1521:xe
dataSource.username=admin
dataSource.password=
参照:https://stackoverflow.com/questions/23172643/how-to-set-up-datasource-with-spring-for-hikaricp
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/164195.html