---
title: "配置proxool不能实例化ProxoolConnectionProvider问题的解决"
author: "YYZhQ"
date: "2012-04-24T10:48:00Z"
tags: []
slug: "proxool-proxoolconnectionprovider"
draft: false
lastmod: "2012-05-29T09:02:31Z"
id: 1543350
url: "https://yyzhq.iteye.com/blog/1543350"
---

配置proxool，加载了proxool的包，一直报错，看错误提示，说不能实例化ProxoolConnectionProvider，查hibernate核心包，里面connection里确实没有这个东东，后来才知道要加载一个hibernate-proxool包才行，可所有配置的教程都没提过，是不是这是该默认知道的东西，我了解的东西太少了？

在maven里加入这个包的最新版本4.1，却发现还是不行，解包一看，4.1里面ProxoolConnectionProvider的pakage路径换了，再晕，这也没事换换啊。因为前面的东西有基于hibernate 3.5.1的，干脆换成3.5.1版本，OK了。

现在将我的spring+struts+jpa(hibernate)+proxool的配置文件贴出来，希望对大家有用，不过目前我的配置会报一个jndi找不到路径名的警告，但不影响运行，这个问题还待解决，见我博客上一篇文章，求解答啊：[http://blog.csdn.net/yyzhq/article/details/7484620](http://blog.csdn.net/yyzhq/article/details/7484620)

**WEB-INF/web.xml**

&lt;?xml version="1.0" encoding="UTF-8"?&gt;  
&lt;web-app xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)" xmlns="[http://java.sun.com/xml/ns/javaee](http://java.sun.com/xml/ns/javaee)" xmlns:web="[http://java.sun.com/xml/ns/javaee/web-app\_2\_5.xsd](http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd)" xsi:schemaLocation="[http://java.sun.com/xml/ns/javaee](http://java.sun.com/xml/ns/javaee)[http://java.sun.com/xml/ns/javaee/web-app\_2\_5.xsd](http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd)" id="struts2springjpa" version="2.5"&gt;  
&lt;display-name&gt;Struts 2 Spring JPA Example&lt;/display-name&gt;  
&lt;welcome-file-list&gt;  
&lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;  
&lt;/welcome-file-list&gt;  
&lt;filter&gt;  
&lt;filter-name&gt;Spring OpenEntityManagerInViewFilter&lt;/filter-name&gt;  
&lt;filter-class&gt;  
org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter  
&lt;/filter-class&gt;  
&lt;/filter&gt;  
&lt;filter-mapping&gt;  
&lt;filter-name&gt;Spring OpenEntityManagerInViewFilter&lt;/filter-name&gt;  
&lt;url-pattern&gt;/\*&lt;/url-pattern&gt;  
&lt;/filter-mapping&gt;  
&lt;filter&gt;  
&lt;filter-name&gt;struts2&lt;/filter-name&gt;  
&lt;filter-class&gt;org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter&lt;/filter-class&gt;  
&lt;/filter&gt;  
&lt;filter-mapping&gt;  
&lt;filter-name&gt;struts2&lt;/filter-name&gt;  
&lt;url-pattern&gt;/\*&lt;/url-pattern&gt;  
&lt;/filter-mapping&gt;  
&lt;context-param&gt;  
&lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;  
&lt;param-value&gt;classpath:applicationContext.xml&lt;/param-value&gt;  
&lt;/context-param&gt;  
&lt;listener&gt;  
&lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;  
&lt;/listener&gt;  
&lt;/web-app&gt;

**WEB-INF/classes/applicationContext.xml**

&lt;?xml version="1.0" encoding="UTF-8"?&gt;  
&lt;beans xmlns="[http://www.springframework.org/schema/beans](http://www.springframework.org/schema/beans)"  
xmlns:context="[http://www.springframework.org/schema/context](http://www.springframework.org/schema/context)"  
xmlns:tx="[http://www.springframework.org/schema/tx](http://www.springframework.org/schema/tx)"  
xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)"  
xmlns:aop="[http://www.springframework.org/schema/aop](http://www.springframework.org/schema/aop)"  
xmlns:jdbc="[http://www.springframework.org/schema/jdbc](http://www.springframework.org/schema/jdbc)"  
xsi:schemaLocation="  
[http://www.springframework.org/schema/beans](http://www.springframework.org/schema/beans)  
[http://www.springframework.org/schema/beans/spring-beans.xsd](http://www.springframework.org/schema/beans/spring-beans.xsd)  
[http://www.springframework.org/schema/aop](http://www.springframework.org/schema/aop)  
[http://www.springframework.org/schema/aop/spring-aop.xsd](http://www.springframework.org/schema/aop/spring-aop.xsd)  
[http://www.springframework.org/schema/tx](http://www.springframework.org/schema/tx)  
[http://www.springframework.org/schema/tx/spring-tx-3.0.xsd](http://www.springframework.org/schema/tx/spring-tx-3.0.xsd)  
[http://www.springframework.org/schema/jdbc](http://www.springframework.org/schema/jdbc)  
[http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd](http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd)  
[http://www.springframework.org/schema/context](http://www.springframework.org/schema/context)  
[http://www.springframework.org/schema/context/spring-context-3.0.xsd](http://www.springframework.org/schema/context/spring-context-3.0.xsd)"&gt;

&lt;!-- scans the classpath for annotated components (including @Repostory  
and @Service that will be auto-registered as Spring beans --&gt;  
&lt;context:component-scan base-package="com.yesrj.ppm.global.system" /&gt;

&lt;!-- methods or classes needing to run in a complete transaction will  
be annotated with Transactional --&gt;  
&lt;tx:annotation-driven /&gt;

&lt;!-- Creates a data source that can provide a connection to in-memory embedded database populated  
with test data  
see: [http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/ch12s08.html](http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/ch12s08.html) --&gt;

&lt;!-- This will ensure that hibernate or jpa exceptions are automatically translated into  
Spring's generic DataAccessException hierarchy for those classes annotated with Repository  
For example see PersonDaoJpa--&gt;  
&lt;bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/&gt;

&lt;!-- JPA Entity Manager Factory --&gt;  
&lt;bean id="entityManagerFactory"  
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;  
&lt;property name="persistenceXmlLocation" value="META-INF/persistence.xml" /&gt;  
&lt;property name="persistenceUnitName" value="springJpaPersistenceUnit" /&gt;  
&lt;/bean&gt;

&lt;!-- bean post-processor for JPA annotations --&gt;  
&lt;bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /&gt;

&lt;!-- Transaction Config --&gt;  
&lt;bean id="transactionManager"  
class="org.springframework.orm.jpa.JpaTransactionManager"&gt;  
&lt;property name="entityManagerFactory" ref="entityManagerFactory"/&gt;  
&lt;/bean&gt;  
&lt;!-- use declarative transaction management --&gt;  
&lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;

&lt;/beans&gt;

**WEB-INF/classes/struts.xml**

&lt;?xml version="1.0" encoding="UTF-8"?&gt;  
&lt;!DOCTYPE struts PUBLIC  
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"  
"[http://struts.apache.org/dtds/struts-2.0.dtd](http://struts.apache.org/dtds/struts-2.0.dtd)"&gt;

&lt;struts&gt;

&lt;constant name="struts.devMode" value="true" /&gt;

&lt;package name="system" extends="struts-default"&gt;

&lt;interceptors&gt;  
&lt;interceptor-stack name="appDefaultStack"&gt;  
&lt;interceptor-ref name="defaultStack"&gt;  
&lt;param name="exception.logEnabled"&gt;true&lt;/param&gt;  
&lt;param name="exception.logLevel"&gt;ERROR&lt;/param&gt;  
&lt;/interceptor-ref&gt;  
&lt;/interceptor-stack&gt;  
&lt;/interceptors&gt;

&lt;default-interceptor-ref name="appDefaultStack" /&gt;

&lt;global-results&gt;  
&lt;result name="error"&gt;/error.jsp&lt;/result&gt;  
&lt;/global-results&gt;

&lt;global-exception-mappings&gt;  
&lt;exception-mapping exception="java.lang.Exception"  
result="error" /&gt;  
&lt;/global-exception-mappings&gt;

&lt;action name="personFinder"  
class="com.yesrj.plm2.global.system.action.PersonFinder" method="execute"&gt;  
&lt;result name="success"&gt;/personinfo.jsp&lt;/result&gt;  
&lt;/action&gt;

&lt;action name="allPersonsFinder"  
class="com.yesrj.plm2.global.system.action.AllPersonsFinder" method="execute"&gt;

&lt;result name="success"&gt;/personsinfo.jsp&lt;/result&gt;

&lt;/action&gt;

&lt;action name="\*PersonUpdate"  
class="com.yesrj.plm2.global.system.action.PersonUpdater" method="{1}"&gt;

&lt;result name="input"&gt;/inputpersonupdate.jsp&lt;/result&gt;  
&lt;result name="success"&gt;/personupdated.jsp&lt;/result&gt;

&lt;/action&gt;

&lt;action name="personDelete"  
class="com.yesrj.plm2.global.system.action.PersonDeleter" method="execute"&gt;

&lt;result name="success"&gt;/persondeleted.jsp&lt;/result&gt;

&lt;/action&gt;

&lt;action name="\*PersonSave" class="com.yesrj.plm2.global.system.action.PersonSaver"  
method="{1}"&gt;

&lt;result name="input"&gt;/inputpersonsave.jsp&lt;/result&gt;  
&lt;result name="success"&gt;/personsaved.jsp&lt;/result&gt;

&lt;/action&gt;

&lt;/package&gt;

&lt;/struts&gt;

**META-INF/persistence.xml**

&lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;  
&lt;persistence xmlns="[http://java.sun.com/xml/ns/persistence](http://java.sun.com/xml/ns/persistence)"  
xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)"  
xsi:schemaLocation="[http://java.sun.com/xml/ns/persistence](http://java.sun.com/xml/ns/persistence)[http://java.sun.com/xml/ns/persistence/persistence\_2\_0.xsd](http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd)"  
version="2.0"&gt;  
&lt;!-- this persistence unit is for the web application --&gt;  
&lt;persistence-unit name="springJpaPersistenceUnit" transaction-type="RESOURCE\_LOCAL"&gt;  
&lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;  
&lt;non-jta-data-source&gt;java:comp/env/jdbc/yespm&lt;/non-jta-data-source&gt;

&lt;class&gt;com.yesrj.ppm.global.system.model.Person&lt;/class&gt;

&lt;properties&gt;  
&lt;property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" /&gt;  
&lt;property name="hibernate.hbm2ddl.auto" value="validate"/&gt;  
&lt;property name="hibernate.show\_sql" value="true"/&gt;  
&lt;property name="hibernate.format\_sql" value="true"/&gt;  
&lt;property name="hibernate.use\_sql\_comments" value="true" /&gt;

&lt;property name="hibernate.connection.provider\_class" value="org.hibernate.connection.ProxoolConnectionProvider"/&gt;  
&lt;property name="hibernate.proxool.pool\_alias" value="MysqlPool"/&gt;  
&lt;property name="hibernate.proxool.xml" value="proxool.xml"/&gt;  
&lt;/properties&gt;  
&lt;/persistence-unit&gt;

&lt;/persistence&gt;

**WEB-INF/classes/proxool.xml**

&lt;?xml version="1.0" encoding="utf-8"?&gt;  
&lt;something-else-entirely&gt;  
&lt;proxool&gt;  
&lt;alias&gt;MysqlPool&lt;/alias&gt;

&lt;driver-url&gt;jdbc:mysql://localhost:3306/yespm&lt;/driver-url&gt;  
&lt;driver-class&gt;com.mysql.jdbc.Driver&lt;/driver-class&gt;  
&lt;driver-properties&gt;  
&lt;property name="user" value="root" /&gt;  
&lt;property name="password" value="root" /&gt;  
&lt;/driver-properties&gt;

&lt;house-keeping-sleep-time&gt;90000&lt;/house-keeping-sleep-time&gt;  
&lt;prototype-count&gt;5&lt;/prototype-count&gt;  
&lt;maximum-connection-count&gt;100&lt;/maximum-connection-count&gt;  
&lt;minimum-connection-count&gt;10&lt;/minimum-connection-count&gt;  
&lt;/proxool&gt;  
&lt;/something-else-entirely&gt;