使用数据源和使用hibernateProperties的区别是什么?我想在我的应用程序中使用带有spring的c3P0。我找到了两种方法,但我无法理解两者之间的区别
第一:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
depends-on="dataSource">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.format_sql">false</prop>
<prop key="hibernate.use_sql_comments">false</prop>
</props>
</property>
<bean id="dataSource" destroy-method="close"
class="com.mchange.v2.c3p0.ComboPooledDataSource" >
<property name="maxPoolSize" value="10" />
<property name="numHelperThreads" value="5" />
</bean>第二:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
>
<property name="hibernateProperties">
<props>
<property name="hibernate.c3p0.maxSize" value="100" />
<property name="hibernate.c3p0.numHelperThreads" value="5" />>
</props>
</property>
</bean>发布于 2013-09-11 15:13:23
第一个是Spring托管数据源,您也可以将其用于JdbcTemplate或其他工作。
第二步,您将得到一个hibernate托管数据源,这个数据源在Spring中是不可重用的。
我强烈建议采用第一种方法,因为它还可以很容易地替换数据源进行测试(用内存中的数据库替换它)或用JNDI查找替换它。
https://stackoverflow.com/questions/18744727
复制相似问题