0

我的应用程序在 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、重置服务器并哭泣,但一切正常。我能做些什么???感谢您的回答!!!

4

2 回答 2

1

我正在使用 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;“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 "。

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

于 2014-01-11T03:59:41.867 回答
0

尝试这个:

<property name="url"> <value>jdbc:mysql://localhost:3306/secretaria?autoReconnect=true</value> </property>

我不确定 Spring 是否支持,但您也可以尝试添加以下属性:

<property name="validationQuery">
<value>选择 1</value> </property>

于 2013-11-06T09:22:17.867 回答