JPA 및 Hibernate를 사용하는 Spring Boot의 연결 시간 초과
JPA-Hibernate 및 MySQL과 함께 Spring Boot를 사용할 때 다음 오류가 발생할 수 있습니다. :
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'.
이 문제는 연결이 장기간 비활성화되어 발생합니다.導致伺服器終止連Line。
권장되지 않는 해결 방법
공통적인 한 가지 그러나 권장되지 않는 접근 방식은 빌릴 때 연결 테스트를 활성화하는 것입니다.
spring.datasource.testOnBorrow=true spring.datasource.validationQuery=SELECT 1
권장 솔루션
보다 포괄적인 솔루션에는 다음이 포함됩니다.
autoReconnect 속성을 포함하도록 spring.datasource.url 설정:
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 참고 사항
In Spring Boot 2.x에서는 연결 풀이 HikariCP로 전환되었습니다. 추가 구성 옵션은 HikariCP 설명서를 참조하세요.
위 내용은 다음은 질문-답변 형식에 초점을 맞추고 기사의 내용을 포괄하는 몇 가지 제목 옵션입니다. **옵션 1(오류에 집중):** * **스프링 부트 JPA/Hibernate: \'Co 수정 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!