2011-04-03 23 views

cevap

4

hazırda olarak, Hibernate CP30 bağlantı havuzu yapılandırabilirsiniz. Bir eğiticiyi görüntüle here. IBM, integrate Hibernate with Spring ile ilgili iyi bir eğiticiye sahiptir. Eğer HikariCP deneyin tüm Java Bağlantı Havuzu sağlayıcılar arasında En İyi kullanmak istiyorsanız

+0

1 C3PO Pool –

7

Sen DBCP bileşenini

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

için DBCP anı gerçek sürümde olduğu 'org.apache.commons.dbcp2.BasicDataSource' – Andremoniy

0
<bean id="dataSource" 
class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
<property name="url" value="<put database connection url here>" /> 
<property name="username" value="XXXXXX" /> 
<property name="password" value="XXXXXXXX" /> 
<property name="driverClassName" value="<database driver here>" /> 
</bean> 

<bean id="pool" class="org.apache.commons.pool.impl.GenericObjectPool"> 
<property name="minEvictableIdleTimeMillis"><value>300000</value></property> 
<property name="timeBetweenEvictionRunsMillis"><value>60000</value></property> 
</bean> 

<bean id="dsConnectionFactory" class="org.apache.commons.dbcp.DataSourceConnectionFactory"> 
<constructor-arg><ref bean="dataSource"/></constructor-arg> 
</bean> 

<bean id="poolableConnectionFactory" class="org.apache.commons.dbcp.PoolableConnectionFactory"> 
<constructor-arg index="0"><ref bean="dsConnectionFactory"/></constructor-arg> 
<constructor-arg index="1"><ref bean="pool"/></constructor-arg> 
<constructor-arg index="2"><null/></constructor-arg> 
<constructor-arg index="3"><null/></constructor-arg> 
<constructor-arg index="4"><value>false</value></constructor-arg> 
<constructor-arg index="5"><value>true</value></constructor-arg> 
</bean> 

<bean id="pooledDS" class="org.apache.commons.dbcp.PoolingDataSource" depends-on="poolableConnectionFactory"> 
<constructor-arg><ref bean="pool"/></constructor-arg> 
</bean> 
1

kullanabilirsiniz.

<beans:bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close"> 
       <beans:property name="dataSourceClassName" value="com.mysql.jdbc.jdbc2.optional.MysqlDataSource"/> 
       <beans:property name="maximumPoolSize" value="5" /> 
       <beans:property name="maxLifetime" value="30000" /> 
       <beans:property name="idleTimeout" value="30000" /> 
       <beans:property name="dataSourceProperties"> 
          <beans:props> 
           <beans:prop key="url">jdbc:mysql://localhost:3306/exampledb</beans:prop> 
           <beans:prop key="user">root</beans:prop> 
           <beans:prop key="password"></beans:prop> 
           <beans:prop key="prepStmtCacheSize">250</beans:prop> 
           <beans:prop key="prepStmtCacheSqlLimit">2048</beans:prop> 
           <beans:prop key="cachePrepStmts">true</beans:prop> 
           <beans:prop key="useServerPrepStmts">true</beans:prop> 
          </beans:props> 
       </beans:property> 
</beans:bean> 

sonra EntityManagerFactory fasulye oluşturmak için bu veri kaynağı kullanmak: olarak sunucu uygulaması-bağlamında HikariCP kullanarak bir veri kaynağı fasulye yapılandırma. İndirilecek örnek proje ile tam örnek linkinde bulunabilir: http://frameworkonly.com/hikaricp-connection-pooling-in-spring-hibernate-jpa/

+0

bu bağlantıyı cevap olsa Soru, cevabın temel kısımlarını buraya dahil etmek ve referans için bağlantı sağlamak daha iyidir. Bağlantılı sayfa değiştiğinde yalnızca bağlantı yanıtları geçersiz olabilir. – Ram

+0

Yanıt güncellendi. –

İlgili konular