gpt4 book ai didi

Java Spring Hibernate 通信链路故障

转载 作者:行者123 更新时间:2023-12-01 13:53:08 24 4
gpt4 key购买 nike

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

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

关于Java Spring Hibernate 通信链路故障,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19807166/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com