尝试使用Spring WebFlow在Hibernate中配置c3p0池

时间:2012-09-06 18:14:21

标签: java spring hibernate spring-webflow c3p0

我使用Spring在Hibernate中配置内置的c3p0池,但它给我的错误它不喜欢任何C3P0之类的东西:

<prop name="hibernate.c3p0.min_size" value="2" />
<prop name="hibernate.c3p0.max_size" value="5" />

有人可以告诉我为什么吗?

<bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
    <!--suppress InjectionValueTypeInspection -->
    <property name="mappingResources" ref="hibernateMappingList" />
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">net.sf.hibernate.dialect.Oracle9Dialect</prop>
            <prop key="transaction.factory_class">
                net.sf.hibernate.transaction.JDBCTransactionFactory
            </prop>
            <prop key="hibernate.transaction.factory_class">
                net.sf.hibernate.transaction.JDBCTransactionFactory
            </prop>
            <prop key="hibernate.show_sql">false</prop>
            <prop key="hibernate.cglib.use_reflection_optimizer">false</prop>
            <prop key="hibernate.jdbc.batch_size">0</prop>

            <prop name="hibernate.c3p0.min_size" value="2" />
            <prop name="hibernate.c3p0.max_size" value="5" />
            <prop name="hibernate.c3p0.timeout" value="600" />
            <prop name="hibernate.c3p0.max_statements" value="0" />
            <prop name="hibernate.c3p0.idle_test_period" value="300"/>
            <prop name="hibernate.c3p0.acquire_increment" value="1" />
      </props>
    </property>
</bean>

这是我的数据库源信息:

<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>

1 个答案:

答案 0 :(得分:1)

XML错了。在以下部分

       <prop name="hibernate.c3p0.min_size" value="2" />
       <prop name="hibernate.c3p0.max_size" value="5" />
       <prop name="hibernate.c3p0.timeout" value="600" />
       <prop name="hibernate.c3p0.max_statements" value="0" />
       <prop name="hibernate.c3p0.idle_test_period" value="300"/>
       <prop name="hibernate.c3p0.acquire_increment" value="1" />

使用与其他属性相同的格式替换它

       <prop key="key">value</prop>

prop元素使用的属性与property元素不同。