我的应用程序在MySql 5.6中运行,并且正在使用Hibernate,Spring和Tomcat7。在我的应用程序在我的个人计算机(Windows 7 32位)上完美运行之前,我将其移至服务器(Windows Server 2008 64位)上。

当我启动服务器时,一切正常,直到尝试加载该库"org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider".

实际上,具体的行是:

INFORMACIÓN: Initializing connection provider:

org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider


在此服务器等待约45秒尝试加载它之后,它出现以下错误:

INFORMACIÓN: Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
nov 06, 2013 9:08:53 AM org.slf4j.impl.JCLLoggerAdapter warn
ADVERTENCIA: SQL Error: 0, SQLState: 08S01
nov 06, 2013 9:08:53 AM org.slf4j.impl.JCLLoggerAdapter error
GRAVE: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
nov 06, 2013 9:08:53 AM org.slf4j.impl.JCLLoggerAdapter warn
ADVERTENCIA: Could not obtain connection to query metadata
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)


这是我的“ applicationContext.xml”,在其中连接数据库并映射资源。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

    <!-- Configuración del datasource para hibernate -->

    <bean
        id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName">
            <value>com.mysql.jdbc.Driver</value>
        </property>
        <property name="url">
            <value>jdbc:mysql://localhost:3306/secretaria</value>
        </property>
        <property name="username">
            <value>secretaria</value>
        </property>
        <property name="password">
            <value>1234</value>
        </property>
    </bean>

    <!-- Factoria de sesiones de Hibernate -->
    <bean
        id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource">
            <ref local="dataSource" />
        </property>
        <property name="mappingResources">
            <list>
                <value>secretaria/beans/prueba.hbm.xml</value>
                <value>secretaria/beans/lotes.hbm.xml</value>
                <value>secretaria/beans/expediente.hbm.xml</value>
                <value>secretaria/beans/prorroga.hbm.xml</value>
                <value>secretaria/beans/plurianual.hbm.xml</value>
                <value>secretaria/beans/modificado.hbm.xml</value>
                <value>secretaria/beans/empresa.hbm.xml</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">
                    org.hibernate.dialect.MySQL5InnoDBDialect
                </prop>
                <prop key="hibernate.hbm2ddl.auto">
                    update
                </prop>
                <prop key="hibernate.show_sql">
                    true
                </prop>
                <prop key="hibernate.format_sql">
                    true
                </prop>
            </props>
        </property>
    </bean>

    <!-- Interceptor para transacciones de Hibernate -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory">
            <ref bean="sessionFactory" />
        </property>
    </bean>

    <import resource="classpath:actions.spring.xml"/>
    <import resource="classpath:dao.spring.xml"/>
    <import resource="classpath:services.spring.xml"/>
</beans>


我试图更新springframeworks库,tomcat,重置服务器并哭泣,但是一切正常。我能做什么???感谢您的回答!!!

最佳答案

我正在使用Spring和MyBatis,并且与您有相同的错误。
我认为您应该为dbcp连接池配置另外两个属性,例如(在application-context.xml中):

    <bean id="vrsRankDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="${jdbc.driverClassName}" />
    <property name="url" value="${vrs_rank.jdbc.url}"/>
    <property name="username" value="${vrs_rank.jdbc.user}" />
    <property name="password" value="${vrs_rank.jdbc.pwd}" />
    <property name="initialSize" value="3"/>
    <property name="testOnBorrow" value="true"/>
    <property name="validationQuery" value="select 1 from dual"/>
</bean>


属性“ initialSize”是创建池时的初始连接数,默认为0;默认值为0。 “ testOnBorrow”属性默认为true,但在您配置属性“ validationQuery”时生效,该属性的值必须为返回至少一行的SELECT语句。

有关更多信息,请参考“ http://commons.apache.org/proper/commons-dbcp/configuration.html”和“ http://dev.mysql.com/doc/refman/5.0/en/connector-j-usagenotes-spring-config-connpooling.html”。

我希望大家都能解决类似的问题。

10-07 22:52