spring集成--数据库连接池配置方法

推荐两种高性能的数据库连接池:
一、Druid数据库连接池
spring配置文件:

<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
        <property name="driverClassName" value="${jdbc.driver}" />
        
        <property name="maxActive" value="10" />
        <property name="minIdle" value="5" />
    bean>

maven引入:

<dependency>
            <groupId>com.alibabagroupId>
            <artifactId>druidartifactId>
        dependency>



二、HikariCP数据库连接池
spring配置文件:

<bean id="dataSourceHikari" class="com.zaxxer.hikari.HikariDataSource"
        destroy-method="shutdown">
        <property name="driverClassName" value="${jdbc.driver}" />
        <property name="jdbcUrl" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
        
        <property name="readOnly" value="false" />
        
        <property name="connectionTimeout" value="30000" />
        
        <property name="idleTimeout" value="600000" />
        
        <property name="maxLifetime" value="1800000" />
        
        <property name="maximumPoolSize" value="60" />
        <property name="minimumIdle" value="10" />
    bean> 

maven引入:

Java 6:
    <dependency>
        <groupId>com.zaxxergroupId>
        <artifactId>HikariCP-java6artifactId>
        <version>2.3.13version>
    dependency>
Java 7:
    <dependency>
        <groupId>com.zaxxergroupId>
        <artifactId>HikariCP-java7artifactId>
        <version>2.4.11version>
    dependency>
Java 8:
    <dependency>
        <groupId>com.zaxxergroupId>
        <artifactId>HikariCPartifactId>
        <version>2.6.0version>
    dependency>

结束!! 希望给各位猿友带来帮助吧!!! 偷偷告诉你们!!!这是我刚写的日记!!

你可能感兴趣的:(sql优化)