首頁 > Java > java教程 > 主體

以下是一些標題選項,重點關注問答格式並涵蓋文章的內容: **選項 1(關注錯誤):** * **Spring Boot JPA/Hibernate:如何修復'Co”

Patricia Arquette
發布: 2024-10-24 18:12:44
原創
343 人瀏覽過

Here are a few title options, focusing on the question-answer format and encompassing the article's content:

**Option 1 (Focus on the Error):**

* **Spring Boot   JPA/Hibernate: How to Fix

Spring Boot 與JPA 和Hibernate 的連接超時

當使用Spring Boot 與JPA-Hibernate 和MySQL 時,您可能會遇到以下錯誤:

Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 56,006,037 milliseconds ago.  The last packet sent successfully to the server was 56,006,037 milliseconds ago. is longer than the server configured value of 'wait_timeout'.
登入後複製

此問題是由於連線長時間處於不活動狀態,導致伺服器終止連線。

不建議的解決方案

一個常見的解決方案但不鼓勵的方法是在藉用時啟用連接測試:

spring.datasource.testOnBorrow=true
spring.datasource.validationQuery=SELECT 1
登入後複製

推薦的解決方案

更全面的解決方案包括:

  • 設定spring.datasource.url 以包含autoReconnect 屬性:

    spring.datasource.url = jdbc:mysql://localhost:3306/test?autoReconnect=true
    登入後複製
  • 指定最大活動連線數:
    spring.datasource.max-active=10
    登入後複製
  • 指定初始連線:
    spring.datasource.initial-size=5
    登入後複製
  • 指定初始連線:

    spring.datasource.max-idle=5
    spring.datasource.min-idle=1
    登入後複製
    設定最大和最小空閒連線:
  • spring.datasource.test-while-idle=true
    spring.datasource.test-on-borrow=true
    登入後複製
    啟用連線驗證:
  • spring.datasource.validation-query=SELECT 1
    spring.datasource.time-between-eviction-runs-millis=5000
    spring.datasource.min-evictable-idle-time-millis=60000
    登入後複製
    指定驗證

HikariCP 的注意事項

中Spring Boot 2.x,連接池已切換為HikariCP。如需更多設定選項,請參閱 HikariCP 文件。

以上是以下是一些標題選項,重點關注問答格式並涵蓋文章的內容: **選項 1(關注錯誤):** * **Spring Boot JPA/Hibernate:如何修復'Co”的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:php
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!