Caused by: com.mchange.v2.resourcepool.ResourcePoolException: Attempted to use a closed or broken resource pool
at com.mchange.v2.resourcepool.BasicResourcePool.ensureNotBroken(BasicResourcePool.java:1735)
at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:573)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:526)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutAndMarkConnectionInUse(C3P0PooledConnectionPool.java:755)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:682)
... 88 more
四月 20, 2015 3:17:58 下午 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring FrameworkServlet 'springServlet'
四月 20, 2015 3:18:38 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory ROOT
四月 20, 2015 3:18:39 下午 org.apache.coyote.http11.Http11Protocol start
信息: Starting Coyote HTTP/1.1 on http-8888
四月 20, 2015 3:18:42 下午 org.apache.jk.common.ChannelSocket init
信息: JK: ajp13 listening on /0.0.0.0:8009
四月 20, 2015 3:18:42 下午 org.apache.jk.server.JkMain start
信息: Jk running ID=0 time=0/481 config=null
四月 20, 2015 3:18:42 下午 org.apache.catalina.startup.Catalina start
信息: Server startup in 142564 ms
spring配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<!-- bean的生命周期回调函数 <bean class="com.test.control.MyBeanPostProcessor"/> -->
<import resource="/beans.xml" />
<context:component-scan base-package="com.h3c.itac" />
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="jdbcUrl">
<value>jdbc:mysql://localhost:3306/itac</value>
</property>
<property name="user">
<value>root</value>
</property>
<property name="password">
<value>root</value>
</property>
<!--连接池中保留的最小连接数。 -->
<property name="minPoolSize" value="10" />
<!--连接池中保留的最大连接数。Default: 15 -->
<property name="maxPoolSize" value="100" />
<!--最大空闲时间,1800秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
<property name="maxIdleTime" value="1800" />
<!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->
<property name="acquireIncrement" value="5" />
<property name="maxStatements" value="1000" />
<property name="initialPoolSize" value="10" />
<!--每60秒检查所有连接池中的空闲连接。Default: 0 -->
<property name="idleConnectionTestPeriod" value="60" />
<!--定义在从数据库获取新连接失败后重复尝试的次数。Default: 30 -->
<property name="acquireRetryAttempts" value="30" />
<property name="breakAfterAcquireFailure" value="true" />
<property name="testConnectionOnCheckout" value="false" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.h3c.itac" />
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
hibernate.hbm2ddl.auto=update
hibernate.connection.autocommit=true
hibernate.show_sql=false
hibernate.format_sql=false
hibernate.cache.use_second_level_cache=true
hibernate.cache.use_query_cache=false
hibernate.current_session_context_class=org.springframework.orm.hibernate4.SpringSessionContext
</value>
</property>
</bean>
<bean id="txManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
<property name="nestedTransactionAllowed" value="true" />
</bean>
<bean class="com.h3c.itac.HibernateBaseDao">
</bean>
<tx:annotation-driven transaction-manager="txManager" proxy-target-class="true"
mode="proxy" />
</beans>
使用的jar
antlr-2.7.7.jar
aopalliance.jar
aspectj-1.8.3.jar
aspectjweaver-1.6.9.jar
c3p0-0.9.2.1.jar
commons-logging-1.0.4.jar
dom4j-1.6.1.jar
gson-2.2.4.jar
hibernate-c3p0-4.3.7.Final.jar
hibernate-commons-annotations-4.0.5.Final.jar
hibernate-core-4.3.7.Final.jar
hibernate-jpa-2.1-api-1.0.0.Final.jar
javassist-3.18.1-GA.jar
jboss-logging-3.1.3.GA.jar
jboss-logging-annotations-1.2.0.Beta1.jar
jboss-transaction-api_1.2_spec-1.0.0.Final.jar
log4j-1.2.17.jar
mchange-commons-java-0.2.3.4.jar
mysql-connector-java-5.1.18-bin.jar
slf4j-api-1.6.1.jar
spring-aop-4.1.2.RELEASE.jar
spring-aspects-4.1.2.RELEASE.jar
spring-beans-4.1.2.RELEASE.jar
spring-context-4.1.2.RELEASE.jar
spring-context-support-4.1.2.RELEASE.jar
spring-core-4.1.2.RELEASE.jar
spring-expression-4.1.2.RELEASE.jar
spring-jdbc-4.1.2.RELEASE.jar
spring-orm-4.1.2.RELEASE.jar
spring-security-config-3.2.5.RELEASE.jar
spring-security-core-3.2.5.RELEASE-javadoc.jar
spring-security-core-3.2.5.RELEASE.jar
spring-security-web-3.2.5.RELEASE.jar
spring-tx-4.1.2.RELEASE.jar
spring-web-4.1.2.RELEASE.jar
spring-webmvc-4.1.2.RELEASE.jar
sqlite-jdbc-3.8.6.jar
standard.jar
其实问题很清楚了, Attempted to use a closed or broken resource pool,刚开始看到这句话感觉是数据源问题,然后去检查数据源的相关c3p0的相关jar和配置,网上有种说法是缺少配置:
<property name="acquireRetryAttempts" value="30" />
<property name="breakAfterAcquireFailure" value="true" />
<property name="testConnectionOnCheckout" value="false" />
但是本xml中已经进行了这个配置,所以问题不是在这里,但是比较奇怪的是:cmd命令行可以顺利的连接上mysql
当时还不是特别确定是不是c3p0的问题,所以,就想到用普通的jdbc程序连接一下数据库试试。
首先可以确定的是,我用root用户名和root密码在cmd中是可以连接上mysql的,所以就比较奇怪了,为什么cmd可以,编程却不可以
,最终原因是本地mysql的问题,更换了sqlite数据库,则可以正常运行