ITeye博客

spring + hibernate4 + BoneCP 配置

focus2008 · 2014-07-19 23:19 · java · 编程语言 · Markdown

BoneCP(http://www.jolbox.com/) 号称是最快的java数据库连接池,我们项目中使用的就是它。其与spring,hibernate4的配置如下所示:

<!-- 采用注解驱动事务 -->		
<tx:annotation-driven transaction-manager="transactionManager"/>

<!-- 注解事务扫描的基包路径(DAO, Service) -->
<context:component-scan base-package="com.hz.xcb" />

<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
	<property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<!-- Hibernate SessionFactory -->
   <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
   <!-- Tell hibernate to use our given datasource -->
       <property name="dataSource" ref="dataSource" /> 	   
       <property name="hibernateProperties">
           <props>
              <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
		<prop key="hibernate.hbm2ddl.auto">update</prop> 
              <prop key="hibernate.show_sql">true</prop>
              <prop key="hiberante.format_sql">true</prop>
           </props>
       </property>
       <property name="configLocations">
	<list>
	<value>
		**classpath*:config/hibernate.cfg.xml**
	</value>
	</list>
</property>
   </bean>
 
<!-- Spring bean configuration. Tell Spring to bounce off BoneCP -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.**LazyConnectionDataSourceProxy**">
    <property name="targetDataSource">
        <ref bean="mainDataSource" />
    </property>
</bean>

<!-- BoneCP configuration -->
<bean id="mainDataSource" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close">
    <property name="driverClass" value="com.mysql.jdbc.Driver" />
    <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/dba01?useUnicode=true&amp;characterEncoding=utf8" />
    <property name="username" value="root"/>
    <property name="password" value="xxxxx"/>
    <property name="idleConnectionTestPeriod" value="60"/>
    <property name="idleMaxAge" value="240"/>      
    <property name="maxConnectionsPerPartition" value="60"/>
    <property name="minConnectionsPerPartition" value="2"/>
    <property name="partitionCount" value="3"/>
    <property name="acquireIncrement" value="10"/>                              
    <property name="statementsCacheSize" value="50"/>
    <property name="releaseHelperThreads" value="3"/>
</bean>

其中hibernate.cfg.xml配置如下:

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。