Because the link pool provided by Hibernate is inefficient and has many bugs, It is not officially recommended. We recommend using a connection pool such as proxool to replace hibernate.
This configuration method is used by spring to take over the proxool connection pool, without adding an additional hibernate configuration file and a ing file between the database and persistent objects (using annotations ).
PS: do not forget to add proxool *. jar in the LIB/optional/proxool folder of the hibernate library to classpath. Otherwise, the proxool connection provider class cannot be found.
The spring configuration file (applicationcontext. XML) is as follows:
<? XML version = "1.0" encoding = "UTF-8"?> <Beans xmlns = "http://www.springframework.org/schema/beans" xmlns: context = "http://www.springframework.org/schema/context" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns: Tx = "http://www.springframework.org/schema/tx" xsi: schemalocation = "http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www Warning "> <context: component-scan base-package =" com. baidu "/> <bean id =" sessionfactory class = "org. springframework. orm. hibernate3.annotation. annotationsessionfactorybean "> <description> annotation hibernate from proxool </description> <property name =" packagetoscan "> <Value> COM. baidu. model </value> </property> <property name = "hibernateproperties"> <props> <prop key = "hibernate. proxool. XML "> proxool. XML </prop> <! -- Create the proxool. xml file in the same directory as this file --> <prop key = "hibernate. proxool. pool_alias> dbpool </prop> <! -- The alias and proxool must be ensured. the declaration in the XML file is the same --> <prop key = "hibernate. cglib. use_reflection_optimizer> true </prop> <prop key = "hibernate. connection. release_mode "> auto </prop> <! -- This option must be set to true to ensure the efficiency of the connection pool --> <prop key = "hibernate. show_ SQL "> true </prop> <prop key =" hibernate. connection. provider_class "> Org. hibernate. connection. proxoolconnectionprovider </prop> </props> </property> </bean> <bean id = "txmanager" class = "org. springframework. orm. hibernate3.hibernatetransactionmanager "P: sessionfactory-ref =" sessionfactory "> </bean> <TX: annotation-driven transaction-Manager =" txmanager "/> </beans>
The proxool file corresponding to this file is as follows:
<? XML version = "1.0" encoding = "UTF-8"?> <Something-else-entirely> <proxool> <alias> dbpool </alias> <! -- Same as the preceding definition of database alias --> <driver-URL> JDBC: mysql: // localhost: 3306/springdemo </driver-URL> <! -- Modify according to the category of the database you are using --> <driver-class> COM. mySQL. JDBC. driver </driver-class> <driver-Properties> <property name = "user" value = "root"/> <property name = "password" value = "root"/> </driver-Properties>
This file is easy to set and can be understood literally in English.
Finally, if you are interested, you can add a monitoring link to the Web. xml file. On the monitoring page, observe the time and resource consumption of the connected database after the connection pool is added. There are many tutorials online. However, the simplest way is to download a GUI for observation. No additional code or configuration is required. MySQL, you can use MySQL administer
The above content from: http://www.cnblogs.com/papertigerv5/archive/2011/11/04/2235919.html
Summary:
1. Add proxool-0.9.1.jar to lib
2. Create proxool. xml
3. Modify spring applicationcontext. XML to add the following code:
<Prop key = "hibernate. proxool. xml"> proxool. xml </prop> <! -- Create the proxool. xml file in the same directory as this file --> <prop key = "hibernate. proxool. pool_alias"> dbpool </prop> <! -- The alias and proxool must be ensured. the declaration in the XML file is the same --> <prop key = "hibernate. cglib. use_reflection_optimizer "> true </prop> <prop key =" hibernate. connection. release_mode "> auto </prop> <! -- This option must be set to true to ensure connection pool Efficiency --> <prop key = "hibernate. Connection. provider_class"> org. hibernate. Connection. proxoolconnectionprovider </prop>
<! -- Configure hibernate properties --> <property name = "hibernateproperties"> <props> <prop key = "hibernate. proxool. xml"> proxool. xml </prop> <! -- Create the proxool. xml file in the same directory as this file --> <prop key = "hibernate. proxool. pool_alias"> dbpool </prop> <! -- The alias and proxool must be ensured. the declaration in the XML file is the same --> <prop key = "hibernate. cglib. use_reflection_optimizer "> true </prop> <prop key =" hibernate. connection. release_mode "> auto </prop> <! -- This option must be set to true to ensure connection pool Efficiency --> <prop key = "hibernate. Connection. provider_class"> org. hibernate. Connection. proxoolconnectionprovider </prop> <! -- Whether to display SQL in the background, in development, and off after going online --> <prop key = "hibernate. show_ SQL"> true </prop> <! -- Whether to generate hibernate statistics --> <prop key = "hibernate. generate_statistics "> false </prop> <prop key =" hibernate. connection. setbigstringtryclob "> true </prop> <! -- <Prop key = "hibernate. JDBC. batch_size"> 0 </prop> --> </props> </property>