2017-03-16 10 views
1

この問題の解決方法を実際に見つけようとしましたが、わかりません。私はあなたたちが何をすべきか知っていることを本当に願っていますMySQLとSpring MVC App間の接続に失敗しました

私のSpring MVCアプリケーションがデータベースへの接続を失い始めましたが、その理由がわかりません。それは私を夢中にさせている。

春DBのセットアップ:

spring.datasource.driverClassName=com.mysql.jdbc.Driver 
spring.datasource.url=jdbc:mysql://ip/database-name 
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect 
spring.jpa.show-sql=false 

spring.datasource.tomcat.initialSize=5 
spring.datasource.tomcat.maxActive=55 
spring.datasource.tomcat.maxIdle=21 
spring.datasource.tomcat.minIdle=13 
spring.datasource.tomcat.testWhileIdle=true 
spring.datasource.tomcat.timeBetweenEvictionRunsMillis=34000 
spring.datasource.tomcat.minEvictableIdleTimeMillis=55000 
spring.datasource.tomcat.validationInterval=34000 
spring.datasource.tomcat.testOnBorrow=true 
spring.datasource.tomcat.validationQuery=SELECT 1 
spring.datasource.tomcat.removeAbandoned=true 
spring.datasource.tomcat.removeAbandonedTimeout=233 

spring.jpa.hibernate.ddl-auto=update 

私がいることを示唆し、答えを見つけたので、私は「真自動再=」を指定しようとした - しかし、それは私の問題を解決していません。

エラーログ:

WARN 5220 --- [-nio-443-exec-6] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: 08S01 
ERROR 5220 --- [-nio-443-exec-6] o.h.engine.jdbc.spi.SqlExceptionHelper : The last packet successfully received from the server was 60,401,089 milliseconds ago. The last packet sent successfully to the server was 60,401,089 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection val 
idity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem. 
ERROR 5220 --- [-nio-443-exec-6] w.a.UsernamePasswordAuthenticationFilter : An internal error occurred while trying to authenticate the user. 

Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 60,401,089 milliseconds ago. The last packet sent successfully to the server was 60,401,089 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem. 
at sun.reflect.GeneratedConstructorAccessor277.newInstance(Unknown Source) ~[na:na] 
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_91] 
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_91] 
at com.mysql.jdbc.Util.handleNewInstance(Util.java:404) ~[mysql-connector-java-5.1.38.jar:5.1.38] 
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:981) ~[mysql-connector-java-5.1.38.jar:5.1.38] 
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3652) ~[mysql-connector-java-5.1.38.jar:5.1.38] 
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2460) ~[mysql-connector-java-5.1.38.jar:5.1.38] 
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2625) ~[mysql-connector-java-5.1.38.jar:5.1.38] 
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2551) ~[mysql-connector-java-5.1.38.jar:5.1.38] 
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861) ~[mysql-connector-java-5.1.38.jar:5.1.38] 
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1962) ~[mysql-connector-java-5.1.38.jar:5.1.38] 
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:82) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final] 
... 111 common frames omitted 
Caused by: java.net.SocketException: Broken pipe 
at java.net.SocketOutputStream.socketWrite0(Native Method) ~[na:1.8.0_91] 
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109) ~[na:1.8.0_91] 
at java.net.SocketOutputStream.write(SocketOutputStream.java:153) ~[na:1.8.0_91] 
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82) ~[na:1.8.0_91] 
at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126) ~[na:1.8.0_91] 
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3633) ~[mysql-connector-java-5.1.38.jar:5.1.38] 
... 117 common frames omitted 

感謝。

私は同様の問題に直面していた

答えて

0

、2つのことを試してみてください。私はidleConnectionTestPeriodを設定し、自分のアプリケーションにC3P0を使用していたspring.datasource.url=jdbc:mysql://ip/database-name

  • spring.datasource.url=jdbc:mysql://ip/database-name?autoReconnect=true

    1. 変更とpreferredTestQueryは私の問題を解決し

      <!-- DB Configuration --> 
      <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> 
          <property name="jdbcUrl" value="${jdbc_url}" /> 
          <property name="user" value="${jdbc_username}" /> 
          <property name="password" value="${jdbc_password}" /> 
          <property name="driverClass" value="${jdbc_driver_class}" /> 
      
          <!-- these are C3P0 properties --> 
          <property name="acquireIncrement" value="1" /> <!-- Determines how many connections at a time c3p0 will try to acquire when the pool is exhausted. --> 
          <property name="minPoolSize" value="${jdbc_min_pool_size}" /> 
          <property name="maxPoolSize" value="${jdbc_max_pool_size}" /> 
          <property name="maxIdleTime" value="100" /> <!-- Seconds a Connection can remain pooled but unused before being discarded. Zero means idle connections never expire. --> 
      
          <!--set this value less then mysql wait_timeout --> 
          <property name="idleConnectionTestPeriod" value="100"/> <!-- If this is a number greater than 0, C3P0 will test all idle, pooled but unchecked-out connections, every this number of seconds--> 
          <property name="preferredTestQuery" value="select 1"/> <!--a query used to test connections--> 
      </bean> 
      

    あなたのプロパティspring.datasource.tomcat.validationIntervalは同じ。このエラーから、MySQLのwait_timeoutは60,401,089ミリ秒だと思われますので、validationIntervalはそれよりも小さく見えますが、100に減らしてエラーが再発するかどうかを確認してください。それが動作しない場合は、c3p0を設定し、私が述べた設定を使ってみてください。

  • +0

    ありがとうございます!私はそれを試してみて、それがそれを解決するかどうかを見てみましょう:-) – doolylol

    関連する問題