参考了很多网友的文章和文档.现将Spring+Hibernate+Proxool的配置发表如下:
首先是一个普通的Proxool配置文件
proxool.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- the proxool configuration can be embedded within your own application's.
Anything outside the "proxool" tag is ignored. -->
<something-else-entirely>
<proxool>
<alias>DBPool</alias>
<driver-url>jdbc:mysql://localhost:3306/WebShop</driver-url>
<driver-class>org.gjt.mm.mysql.Driver</driver-class>
<driver-properties>
<property name="user" value="root"/>
<property name="password" value="123456"/>
</driver-properties>
<maximum-connection-count>10</maximum-connection-count>
<house-keeping-test-sql>select CURRENT_DATE</house-keeping-test-sql>
</proxool>
</something-else-entirely>
<!-- the proxool configuration can be embedded within your own application's.
Anything outside the "proxool" tag is ignored. -->
<something-else-entirely>
<proxool>
<alias>DBPool</alias>
<driver-url>jdbc:mysql://localhost:3306/WebShop</driver-url>
<driver-class>org.gjt.mm.mysql.Driver</driver-class>
<driver-properties>
<property name="user" value="root"/>
<property name="password" value="123456"/>
</driver-properties>
<maximum-connection-count>10</maximum-connection-count>
<house-keeping-test-sql>select CURRENT_DATE</house-keeping-test-sql>
</proxool>
</something-else-entirely>
这里面的内容没什么好讲的了,如果不懂的话参考本blog的其它相关文章
Spring的配置文件
applicationContext.xml
1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
3<beans>
4 <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" singleton="true">
5 <property name="hibernateProperties">
6 <props>
7 <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
8 <prop key="hibernate.show_sql">true</prop>
9 <prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
10 <prop key="hibernate.proxool.xml">proxool.xml</prop>
11 <prop key="hibernate.proxool.pool_alias">DBPool</prop>
12 </props>
13 </property>
14 <property name="mappingResources">
15 <list>
16 <value>User.hbm.xml</value>
17 </list>
18 </property>
19 </bean>
20 <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
21 <property name="sessionFactory">
22 <ref local="mySessionFactory"/>
23 </property>
24 </bean>
25 <bean id="userDao" class="com.ycoe.blog2.impl.UserDaoImpl">
26 <property name="sessionFactory">
27 <ref local="mySessionFactory"/>
28 </property>
29 </bean>
30</beans>
31
2<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
3<beans>
4 <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" singleton="true">
5 <property name="hibernateProperties">
6 <props>
7 <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
8 <prop key="hibernate.show_sql">true</prop>
9 <prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
10 <prop key="hibernate.proxool.xml">proxool.xml</prop>
11 <prop key="hibernate.proxool.pool_alias">DBPool</prop>
12 </props>
13 </property>
14 <property name="mappingResources">
15 <list>
16 <value>User.hbm.xml</value>
17 </list>
18 </property>
19 </bean>
20 <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
21 <property name="sessionFactory">
22 <ref local="mySessionFactory"/>
23 </property>
24 </bean>
25 <bean id="userDao" class="com.ycoe.blog2.impl.UserDaoImpl">
26 <property name="sessionFactory">
27 <ref local="mySessionFactory"/>
28 </property>
29 </bean>
30</beans>
31
这里有几个要注意的地方:
1.这两个文档的放置目录的问题.说得简单些就是要放在classpath路径中.
2.hibernate.proxool.pool_alias要和proxool.xml中配置的一样!
3.mappingResources可以将它从这个配置文件中独立来开,以提高配置的结构,易于修改,同理也适用于其它的事务配置
有些配置细节不再在些处细说,详见本blog的其它文章!
相关文件下载:https://files.cnblogs.com/ycoe/Spring+Proxool+Hibernate.rar(里面附详细使用说明)
可以说已经配置完成了,就是这么简单!可以看到Spring的优美,简单,真让人拍案叫绝
--原创文章,可以随意复制,发表,但请注明出处和作者信息,谢谢合作!
By YCOE