项目结构是:springmvc +hibernate+mysql,

数据库连接池:C3P0

服务器使用的是tomcat7

出现的状况是:访问的时候经常出现404错误

实验的过程刚开始以为是数据库版本的问题,但是用过了各个版本,包括操作系统用windows,linux都试过,错误是一样的。

也试过网络上面讲的改变mysql的配置文件,增加连接时间,但是错误依旧。

在和我们公司的汪总和程序员沟通之后,终于得到解决。

原因是

HIBERNATE的配置不一定能管理动C3P0

出现的错误提示:

HTTP Status 500 - Request processing failed; nested exception is org.springframework.orm.hibernate3.HibernateSystemException: JDBC commit failed; nested exception is org.hibernate.TransactionException: JDBC commit failed

type Exception report

message Request processing failed; nested exception is org.springframework.orm.hibernate3.HibernateSystemException: JDBC commit failed; nested exception is org.hibernate.TransactionException: JDBC commit failed

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.orm.hibernate3.HibernateSystemException: JDBC commit failed; nested exception is org.hibernate.TransactionException: JDBC commit failed

org.springframework.orm.hibernate3.HibernateSystemException: JDBC commit failed; nested exception is org.hibernate.TransactionException: JDBC commit failed

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 149,464 milliseconds ago.  The last packet sent successfully to the server was 18,923 milliseconds ago.

java.net.SocketTimeoutException: Read timed out

解决问题的办法是改变spring的配置文件applicationContext.xml,增加相关的配置

在<beans>标签内加入下面相关的配置:

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">

<property name="driverClass" value="${jdbc.driver}" />

<property name="jdbcUrl" value="${jdbc.url}" />

<property name="user" value="${jdbc.username}" />

<property name="password" value="${jdbc.password}" />

<property name="initialPoolSize" value="${connection_pools.initial_pool_size}" />

<property name="minPoolSize" value="${connection_pools.min_pool_size}" />

<property name="maxPoolSize" value="${connection_pools.max_pool_size}" />

<property name="maxIdleTime" value="${connection_pools.max_idle_time}" />

<property name="acquireIncrement" value="${connection_pools.acquire_increment}" />

<property name="checkoutTimeout" value="${connection_pools.checkout_timeout}" />

<property name="testConnectionOnCheckin" value="false"/>

             <property name="testConnectionOnCheckout" value="true"/>

             <property name="preferredTestQuery" value="SELECT 1"/>

</bean>

配置完重启服务器就可以了