0

我正在尝试使用 Spring WebFlow 和 MySQL 在 Hibernate 中使用 C3P0 Pooling 设置池,但我想让 Hibernate 管理池而不是 mysql,所以我设置我的 jdbc.properties 文件和我的 database.xml 文件并运行我的项目并检查了与数据库的连接,看起来如果我在 MySQL 端更改 database.minPoolSize 属性,它可以工作,但如果我在 Hibernate 大小上更改它们,它就不起作用。有人可以查看我的文件并让我知道您的想法:

jdbc.properties:

#
# database
#
database.driver=com.mysql.jdbc.Driver
database.url=jdbc:mysql://xxx
database.user=xxx
database.password=xxx
database.acquireIncrement=1
database.minPoolSize=5
database.maxPoolSize=25
database.maxIdleTime=1
#
# Hibernate
#
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
hibernate.show_sql=false
format_sql=false
hibernate.use_sql_comments=false;
#
# C3P0
#
hibernate.c3p0.min_size=5
hibernate.c3p0.max_size=25
hibernate.c3p0.timeout=600
hibernate.c3p0.max_statements=0
hibernate.c3p0.idle_test_period=300
hibernate.c3p0.acquire_increment=5

这是我的 database.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc"

    xsi:schemaLocation="http://www.springframework.org/schema/beans 
                            http://www.springframework.org/schema/beans/spring-beans.xsd
                            http://www.springframework.org/schema/context 
                            http://www.springframework.org/schema/context/spring-context-3.0.xsd
                            http://www.springframework.org/schema/tx
                            http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                            http://www.springframework.org/schema/jdbc
                            http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd">



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

    <context:component-scan base-package="org.uftwf" />

    <tx:annotation-driven transaction-manager="hibernateTransactionManager" />


    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
        destroy-method="close">

        <!-- these are C3P0 properties -->
        <property name="acquireIncrement" value="${database.acquireIncrement}" />
        <property name="minPoolSize" value="${database.minPoolSize}" />
        <property name="maxPoolSize" value="${database.maxPoolSize}" /> 
        <property name="maxIdleTime" value="${database.maxIdleTime}" />

        <property name="driverClass" value="${database.driver}" />
        <property name="jdbcUrl" value="${database.url}" />
        <property name="user" value="${database.user}" />
        <property name="password" value="${database.password}" />
    </bean>

    <!-- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" 
        destroy-method="close"> <property name="driverClassName" value="${database.driver}" 
        /> <property name="url" value="${database.url}" /> <property name="username" 
        value="${database.user}" /> <property name="password" value="${database.password}" 
        /> </bean> -->

    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="annotatedClasses">
            <list>
                <value>org.uftwf.schoolvisit.model.VisitModel</value>
                <value>org.uftwf.schoolvisit.model.NameID_lookupModel</value>
                <value>org.uftwf.schoolvisit.model.School_lookupModel</value>
            </list>
        </property>

        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>


                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                <prop key="hibernate.use_sql_comments">${hibernate.use_sql_comments}</prop>
                <prop key="format_sql">${format_sql}</prop>
                <prop key="hibernate.c3p0.min_size">10</prop>
                <prop key="hibernate.c3p0.max_size">25</prop>
                <prop key="hibernate.c3p0.timeout">600</prop>
                <prop key="hibernate.c3p0.max_statements">0</prop>
                <prop key="hibernate.c3p0.idle_test_period">300</prop>
                <prop key="hibernate.c3p0.acquire_increment">5</prop>
            </props>
        </property>
    </bean>

    <bean id="hibernateTransactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
</beans>

为什么 C3P0 不使用休眠属性而是使用 mysql 一次?

4

1 回答 1

0

您正在C3P0 bean使用普通属性定义您的。更改${database...}为所需的关联键。

于 2012-09-06T20:03:56.920 回答