Connection lost overnight (spring boot + mysql)

后端 未结 3 812
温柔的废话
温柔的废话 2020-12-19 01:47

My spring boot application always show me this whitelabel error in the morning: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.Persi

相关标签:
3条回答
  • 2020-12-19 02:17

    You can fix this by setting the property wait_timeout = 31536000 in the DB Server. This is equivalent to one year. In case if you DB is running in the AWS environment, go to Parameters group-> create a new group -> set wait_timeout = 31536000 and assign the newly created parameters group to your RDS instance. If you want to fix this in the spring boot instance, you can fix by C3P0 settings only, but I haven't tried that.

    0 讨论(0)
  • 2020-12-19 02:18

    You can also see this link It tells you to include the following lines in the application.properties file.

    spring.datasource.testWhileIdle = true
    spring.datasource.timeBetweenEvictionRunsMillis = 3600000
    spring.datasource.validationQuery = SELECT 1
    
    0 讨论(0)
  • 2020-12-19 02:34

    Check this answer: Spring Boot JPA - configuring auto reconnect

    In short, you'll need:

    spring.datasource.testOnBorrow=true
    spring.datasource.validationQuery=SELECT 1
    
    0 讨论(0)
提交回复
热议问题