熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java開源技術 >> 正文

Spring配C3P0連接池

2022-06-13   來源: Java開源技術 

  applicationContextxml 文件 <?xml version= encoding=UTF?>
    <beans xmlns=
        xmlns:xsi=instance
        xmlns:jee=
        xsi:schemaLocation= beansxsd
                jeexsd>
        <bean id=dataSource
            class=commchangevcpComboPooledDataSource
            destroymethod=close>
            <property name=driverclass>
                <value>commysqljdbcDriver</value>
            </property>
            <property name=jdbcUrl>
                <value>jdbc:mysql://:/DBName?useUnicode=true&amp;characterEncoding=GBK</value>
            </property>
            <property name=user>
                <value>root</value>
            </property>
            <property name=password>
                <value>root</value>
            </property>

  <!連接池中保留的最小連接數>
            <property name=minPoolSize>
                <value></value>
            </property>

  <!連接池中保留的最大連接數Default: >
            <property name=maxPoolSize>
                <value></value>
            </property>

  <!初始化時獲取的連接數取值應在minPoolSize與maxPoolSize之間Default: >
            <property name=initialPoolSize>
                <value></value>
            </property>

  <!最大空閒時間秒內未使用則連接被丟棄若為則永不丟棄Default: >
            <property name=maxIdleTime>
                <value></value>
            </property>

  <!當連接池中的連接耗盡的時候cp一次同時獲取的連接數Default: >
            <property name=acquireIncrement>
                <value></value>
            </property>

  <!JDBC的標准參數用以控制數據源內加載的PreparedStatements數量但由於預緩存的statements   屬於單個connection而不是整個連接池所以設置這個參數需要考慮到多方面的因素   如果maxStatements與maxStatementsPerConnection均為則緩存被關閉Default: >
            <property name=maxStatements>
                <value></value>
            </property>

  <!秒檢查所有連接池中的空閒連接Default: >
            <property name=idleConnectionTestPeriod>
                <value></value>
            </property>

  <!定義在從數據庫獲取新連接失敗後重復嘗試的次數Default: >
            <property name=acquireRetryAttempts>
                <value></value>
            </property>

  <!獲取連接失敗將會引起所有等待連接池來獲取連接的線程拋出異常但是數據源仍有效   保留並在下次調用getConnection()的時候繼續嘗試獲取連接如果設為true那麼在嘗試   獲取連接失敗後該數據源將申明已斷開並永久關閉Default: false>
            <property name=breakAfterAcquireFailure>
                <value>true</value>
            </property>

  <!因性能消耗大請只在需要的時候使用它如果設為true那麼在每個connection提交的   時候都將校驗其有效性建議使用idleConnectionTestPeriod或automaticTestTable   等方法來提升連接測試的性能Default: false >
            <property name=testConnectionOnCheckout>
                <value>false</value>
            </property>
        </bean>
        <! Hibernate SessionFactory >
        <bean id=sessionFactory
            class=orgspringframeworkormhibernateLocalSessionFactoryBean>
            <property name=dataSource>
                <ref local=dataSource />
            </property>
            <property name=mappingResources>
                <list>
                    <value>com/xh/hibernate/vo/Userhbmxml</value>
                </list>
            </property>
            <property name=hibernateProperties>
                <props>
                    <prop key=hibernatedialect>orghibernatedialectMySQLDialect</prop>
                    <prop key=hibernateshow_sql>true</prop>
                    <prop key=hibernategenerate_statistics>true</prop>
                    <prop key=nnectionrelease_mode>auto</prop>
                    <prop key=hibernateautoReconnect>true</prop>
                </props>
            </property>
        </bean>
    </beans>


From:http://tw.wingwit.com/Article/program/Java/ky/201311/28620.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.