网上关于C3P0在spring中的配置,几乎没有完全正确的(至少我还没发现)。查了c3p0的文档,又试验过N次。得出如下配置是正确的:
<!-- com.mchange.v2.c3p0.ComboPooledDataSource -->
<bean id="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass"
value="oracle.jdbc.driver.OracleDriver">
</property>
<property name="jdbcUrl"
value="jdbc:oracle:thin:@127.0.0.1:1521:db">
</property>
<property name="user" value="123"></property>
<property name="password" value="123"></property>
<property name="minPoolSize"><value>1</value></property>
<property name="maxPoolSize"><value>20</value></property>
<property name="maxIdleTime"><value>1800</value></property>
<property name="acquireIncrement"><value>2</value></property>
<property name="maxStatements"><value>0</value></property>
<property name="initialPoolSize"><value>2</value></property>
<property name="idleConnectionTestPeriod"><value>1800</value></property>
<property name="acquireRetryAttempts"><value>30</value></property>
<property name="breakAfterAcquireFailure"><value>true</value></property>
<property name="testConnectionOnCheckout"><value>false</value></property>
</bean>
<!--
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="oracle.jdbc.driver.OracleDriver">
</property>
<property name="url"
value="jdbc:oracle:thin:@221.232.148.68:1521:starmap">
</property>
<property name="username" value="htgis"></property>
<property name="password" value="htgis"></property>
</bean>
-->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.connection.release_mode">auto</prop>
<prop key="hibernate.autoReconnect">true</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
<!--
<prop key="hibernate.c3p0.min_size">5</prop>
<prop key="hibernate.c3p0.max_size">20</prop>
<prop key="hibernate.c3p0.timeout">1800</prop>
<prop key="hibernate.c3p0.max_statements">50</prop>
<prop key="hibernate.show_sql">false</prop>-->
</props>
</property>
<property name="mappingResources">
<list>
<value>ht/gisoa/entity/CmppSubmitCache.hbm.xml</value>
<value>ht/gisoa/entity/CmppDeliver.hbm.xml</value>
<value>ht/gisoa/entity/CmppSubmit.hbm.xml</value>
<value>ht/gisoa/entity/CmppReport.hbm.xml</value>
<value>ht/gisoa/entity/SGpstraceinfo.hbm.xml</value>
<value>ht/gisoa/entity/SDeviceinfo.hbm.xml</value>
<value>ht/gisoa/entity/SLbstraceinfo.hbm.xml</value>
<value>ht/gisoa/entity/Lbsschemainfo.hbm.xml</value>
</list>
</property>
</bean>