Spring Comments (eight) ------ common connection pool configuration

First of all, we are ready to Jdbc properties file

jdbc.properties, save the connection information for the database, which will help us in the configuration file

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc\:mysql\://localhost\:3306/mybook
jdbc.username=root
jdbc.password=1234

Registration Jdbc configuration properties file as long as the applicationContext.xml (Spring configuration file)

    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="classpath:jdbc.properties"></property>
    </bean>

or

<context:property-placeholder location="classpath:jdbc.properties"/>

A: Spring frame built connection pool (built jar package may be used)

Of course, it is to use spring-jdbc-4.2.0.RELEASE.jar

(Spring configuration file) configuration in applicationContext.xml:

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="${jdbc.driver}"></property>
    <property name="url" value="${jdbc.url}"></property>
    <property name="username" value="${jdbc.username}"></property>
    <property name="password" value="${jdbc.password}"></property>
  </bean>

II: Use c3p0 connection pool

This of course was the introduction of its jar package myself!

I am using here is: com.springsource.com.mchange.v2.c3p0-0.9.1.2.jar

(Spring configuration file) configuration in applicationContext.xml:

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="${jdbc.driver}"></property>
        <property name="url" value="${jdbc.url}"></property>
        <property name="username" value="${jdbc.username}"></property>
        <property name="password" value="${jdbc.password}"></property>
    </bean>

Three: Apache's DBCP connection pool

This of course was the introduction of its jar package myself!

I use here are:

com.springsource.org.apache.commons.dbcp-1.2.2.osgi.jar

com.springsource.org.apache.commons.pool-1.3.0.jar

(Spring configuration file) configuration in applicationContext.xml:

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="${jdbc.driver}"></property>
        <property name="url" value="${jdbc.url}"></property>
        <property name="username" value="${jdbc.username}"></property>
        <property name="password" value="${jdbc.password}"></property>
    </bean>

 IV: Ali Baba frame connection pool druid

This of course was the introduction of its jar package myself!

I use here are:

druid-0.1.18.jar

(Spring configuration file) configuration in applicationContext.xml:

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

 

Guess you like

Origin www.cnblogs.com/deityjian/p/11067518.html