![](/img/trans.png)
[英]what is java.io.EOFException, Message: Can not read response from server. Expected to read 4 bytes, read 0 bytes
[英]MySQL : EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost
我有一个带有石英调度程序的Spring应用程序,用于批处理。 最近4年以来一切正常。 每1分钟运行一次批处理。 但是从最近几天开始,当该批处理试图获取某些数据时,我们突然收到org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Could not open connection
org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Could not open connection
该批次全天运行,但有时会出现此异常,而所有其他批次均无法连接到MySQL。 因此,我们正在重新启动该应用程序,它运行正常。
数据源配置
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="url">
<value>${DATABASE_URL}</value>
</property>
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="username">
<value>${DATABASE_USER}</value>
</property>
<property name="password">
<value>${DATABASE_PASSWORD}</value>
</property>
</bean>
会话工厂连接池配置
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.enable_lazy_load_no_trans">true</prop>
<!-- Configurations specific to c3p0 connection pooling -->
<prop key="hibernate.c3p0.acquire_increment">5</prop>
<prop key="hibernate.c3p0.idle_test_period">1800</prop>
<prop key="hibernate.c3p0.max_size">600</prop>
<prop key="hibernate.c3p0.max_statements">50</prop>
<prop key="hibernate.c3p0.min_size">5</prop>
<prop key="hibernate.c3p0.timeout">1800</prop>
</props>
</property>
<property name="annotatedClasses">
<list> .... </list>
</property>
</bean>
可能是运行您的数据库服务器的mysql问题。
更改数据库服务器中的mysql配置
在[mysqld]部分的mysql.cnf中添加绑定地址
bind-address=your_spring_application_ip
还更改mysql用户的访问主机。 在mysql中运行以下查询
update mysql.user set host='%' where user='your_username';
flush privileges;
然后重启mysql服务
sudo systemctl restart mysql
最近,我们遇到了同样的问题。 我们的应用程序无法连接到AWS Aurora实例。 我们最终将sql驱动程序更改为mariadb。 希望这会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.