gpt4 book ai didi

java - Spring & Hibernate 的连接池

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:33:57 25 4
gpt4 key购买 nike

如何使用 Spring 和 Hibernate 配置连接池?

谢谢

地点

最佳答案

您可以使用 DBCP 组件

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">

<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="initialSize" value="10" />
<property name="maxActive" value="5" />
<property name="maxWait" value="5000" />
</bean>


<!-- Hibernate Configuration -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
p:dataSource-ref="dataSource">
<property name="annotatedClasses">
<list>
<value>com.project.domain.Domain1</value>
<value>com.project.domain.Domain1</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.generate_statistics">
${hibernate.show_statistics}
</prop>
</props>
</property>
</bean>

关于java - Spring & Hibernate 的连接池,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5527887/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com