ssh2整合,不用数据连接池,完全正常;换c3p0就出错!而且启动服务慢,请求响应也很慢!
这个c3p0有什么猫腻?我在applicationContext.xml中如下配置:
- XML code
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" value="classpath:dataSource.properties" /> </bean> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass"> <value>${datasource.driverClassName} </value> </property> <property name="jdbcUrl"> <value>${datasource.url} </value> </property> <property name="user"> <value>${datasource.username} </value> </property> <property name="password"> <value>${datasource.password} </value> </property> <property name="initialPoolSize"> <value>${jdbc.initialPoolSize} </value> </property> <property name="minPoolSize"> <value>${jdbc.minPoolSize} </value> </property> <property name="maxPoolSize"> <value>${jdbc.maxPoolSize} </value> </property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="mappingResources"> <list> <value>ssh2/login/model/User.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.MySQLDialect </prop> <prop key="show_sql">true</prop> </props> </property> </bean>
我也添加c3p0-0.9.1.jar包了,难道还需要其他包?请求半天,浏览器出现如下信息:
Struts Problem Report
Struts has detected an unhandled exception:
Messages: A ResourcePool could not acquire a resource from its primary factory or source.
Connections could not be acquired from the underlying database!
Hibernate operation: Cannot open connection; uncategorized SQLException for SQL [???]; SQL state [null]; error code [0]; Connections could not be acquired from the underlying database!; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!
File: com/mchange/v2/resourcepool/BasicResourcePool.java
Line number: 1,319
Stacktraces
org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: Cannot open connection; uncategorized SQLException for SQL [???]; SQL state [null]; error code [0]; Connections could not be acquired from the underlying database!; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!
为什么啊?请教高手!我半天没弄明白这个问题!
------解决方案--------------------
启动服务很慢,应该是连接池没能连接到数据库,等待超时所以很慢。
但连接池应该后台Console会有错误日志显示出来,而你这里似乎没有贴出来,是不是日志级别设置太高了?
可以自己写个Bean去尝试获取下连接,看看能否得到更详细点的错误信息。
另外,你连接池的每一个配置项后面都多了个空格,这习惯可不好。