Spring/Hibernate/Proxool集成

来源:互联网 发布:java实用教程第三版pdf 编辑:程序博客网 时间:2024/06/06 03:18

参考了很多网友的文章和文档.现将Spring+Hibernate+Proxool的配置发表如下:
    proxool.xml
  

<?xml version="1.0" encoding="UTF-8"?>
<something-else-entirely>
  
<proxool>
    
<alias>DBPool</alias>
    
<driver-url>jdbc:mysql://localhost:3306/db</driver-url>
    
<driver-class>com.mysql.jdbc.Driver</driver-class>
    
<driver-properties>
      
<property name="user" value="root"/>
      
<property name="password" value="123456"/>
    
</driver-properties>
     <
maximum-connection-count>50</maximum-connection-count>
      <minimum-connection-count>10</minimum-connection-count>

    
<house-keeping-test-sql>select CURRENT_DATE</house-keeping-test-sql>
  
</proxool>
</something-else-entirely>

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>     <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" singleton="true">
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
                <prop key="hibernate.proxool.xml">proxool.xml</prop>
                <prop key="hibernate.proxool.pool_alias">DBPool</prop>

                  <prop key="hibernate.connection.release_mode">auto</prop>
            </props>
        </property>
        <property name="mappingResources">
          <list>
              <value>xxxx.hbm.xml</value> 
          </list>
          </property>
    </bean>
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory">
            <ref local="mySessionFactory"/>
        </property>
    </bean>
    <bean id="xxDao" class="xxx.xxxxx.xxxxxx.xxDaoImpl">
        <property name="sessionFactory">
          <ref local="mySessionFactory"/>
        </property>
    </bean>
</beans>

另外一种配置【很少见】:

   <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName">
    <value>org.logicalcobwebs.proxool.ProxoolDriver</value>
    </property>
    <property name="url">
    <value>proxool.db</value>
    </property>
    </bean>

   <bean id="sessionFactory" lazy-init ="true" 
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">   
        <!--   依赖注入数据源,注入正是上文定义的dataSource-->   
        <property name="dataSource"><ref local="dataSource"/></property>   
        <property name="lobHandler" ref="lobHandler"/>
        
        <property name="mappingLocations">   
            <list>   
                <!--以下用来列出所有的PO映射文件-->
     <value>classpath:xxx/xxx/xxx/xx/xxx.hbm.xml</value>
            </list>   
        </property>   
        <!--定义Hibernate的SessionFactory的属性 -->   
        <property name="hibernateProperties">   
            <props>   
                <!-- 指定Hibernate的连接方言-->   
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>   
                <!-- 不同数据库连接,启动时选择create,update,create-drop   -->
                <prop key="hibernate.hbm2ddl.auto">update</prop> 
                <prop key="hibernate.show_sql">false</prop> 
     <prop key="connection.useUnicode">true</prop>
     <prop key="connection.characterEncoding">UTF-8</prop>
                
            </props>   
        </property> 
        
       
    </bean>