日期:2014-05-20  浏览次数:20662 次

spring配置proxool数据连接池的问题,来者有分!
开始的时候,我用的是dbcp的连接池
在spring的配置文件中这么配置连接池部分:
XML code

<!-- 配置DataSource -->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <property name="driverClassName" value="${jdbc.driverClassName}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
    </bean>
    <!--配置hibernate -->
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.format_sql">true</prop>
                  <prop key="hibernate.hbm2ddl.auto">update</prop>
            </props>
        </property>
        <property name="packagesToScan">
            <list>
                <value>com.model</value>
            </list>
        </property>
    </bean>


大家注意,我配置了Datasource(其中${jdbc.username}的是个属性文件,这个大家都知道吧)

可是后来,我看了我们大牛老师的配置文件,他用的proxool作为连接池,这是这样配置的:
XML code

<bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect
                </prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.format_sql">false</prop>
                <prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
                <prop key="connection.provider_class">org.hibernate.connection.ProxoolConnectionProvider
                </prop>
                <prop key="hibernate.proxool.xml">../proxool.xml</prop>
                <prop key="hibernate.proxool.pool_alias">cocacola_sqlserver</prop>
            </props>
        </property>
        <property name="mappingLocations">
            <value>classpath:/com/cocacola/domain/*.hbm.xml
            </value>
        </property>
    </bean>


大家注意, 它并没有配置dataSource,这样可以吗?
proxool.xml:
XML code

<?xml version="1.0" encoding="UTF-8"?>
<something-else-entirely>
    <proxool>
        <alias>cocacola_mysql</alias>
        <driver-url>jdbc:mysql://localhost:3306/cocacola</driver-url>
        <driver-class>com.mysql.jdbc.Driver</driver-class>
        <driver-properties>
            <property name="user" value="root" />
            <property name="password" value="d" />
        </driver-properties>
        <maximum-connection-count>100</maximum-connection-count>
        <minimum-connection-count>10</minimum-connection-count>
        <simultaneous-build-throttle>30</simultaneous-build-throttle>
        <prototype-count>3</prototype-count>
        <house-keeping-test-sql>select 1 from dual</house-keeping-test-sql>
    </proxool>
    <proxool>
        <alias>cocacola_sqlserver</alias>
        <driver-url>jdbc:sqlserver://localhost:1433;databasename=cocacola</driver-url>
        <driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
        <driver-properties>
            <property name="user" value="sa" />
            <property name="password" value="" />
        </driver-properties>
        <maximum-connection-count>100</maximum-connection-count>
        <minimum-connection-count>10</minimum-connection-count>
        <simultaneous-build-throttle>30</simultaneous-build-throttle>
        <prototype-count>3</prototype-count>
        <house-keeping-test-sql>select 1</house-keeping-test-sql>
    </proxool>
</something-else-entirely>