我的应用程序在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,重置服务器并哭,但任何工作都有效。我能做什么???谢谢你的回答!!!
答案 0 :(得分: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”。
我希望你们都能解决类似问题。
答案 1 :(得分:0)
试试这个:
&lt; property name =“url”&gt; &LT;值GT; JDBC:MySQL的://本地主机:3306 / secretaria autoReconnect的=真LT; /值GT; &LT; /性&gt;
我不确定Spring支持,但您也可以尝试添加以下属性:
&lt; property name =“validationQuery”&gt;
&lt; value&gt;选择1&lt; / value&gt; &LT; /性&gt;