簡體   English   中英

Java Spring Hibernate Communications鏈接失敗

[英]Java Spring Hibernate Communications link failure

我的應用程序在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 “。

我希望大家都能解決類似的問題。

嘗試這個:

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

我不確定Spring是否支持,但是您也可以嘗試添加以下屬性:

<property name =“ validationQuery”>
<value>選擇1 </ value> </ property>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM