【问题标题】:Spring boot and hibernate mysql database connection keep on disconnectingSpring boot和hibernate mysql数据库连接不断断开
【发布时间】:2016-12-20 19:22:39
【问题描述】:

我的 Web 应用程序现在运行良好,并将数据保存到 mysql 数据库。只有我无法理解连接的一件事是,它会在一段时间后断开数据库上的连接,我需要继续停止并重新启动 Tomcat 以保持与应用程序的连接处于活动状态。 我需要在 tomcat 网络服务器或 mysql 数据库中设置任何会话超时吗?

下面是我在 spring boot 中的 application.properties。

debug=true

spring.datasource.url=jdbc:mysql://localhost/database
spring.datasource.username=username
spring.datasource.password=pass
spring.datasource.driverClassName=com.mysql.jdbc.Driver

spring.jpa.hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
spring.jpa.generate-ddl=true
spring.jpa.show-sql=true

logging.level.org.hibernate.SQL=DEBUG


Below is the exception:

Exception: org.springframework.dao.DataAccessResourceFailureException: could not prepare statement; nested exception is org.hibernate.exception.JDBCConnectionException: could not prepare statement

感谢您的帮助。

唐纳德

【问题讨论】:

  • 请发布您的 jdbc 连接 url。一定是这样的url="jdbc:mysql://localhost:3306/hposg
  • 请查看this是否有帮助
  • spring.datasource.testOnBorrow=true spring.datasource.validationQuery=SELECT 1

标签: mysql spring hibernate tomcat spring-boot


【解决方案1】:

这对我有用。只需添加到您的 application.properties

spring.datasource.testOnBorrow=true
spring.datasource.validationQuery=SELECT 1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-20
    • 1970-01-01
    • 2019-04-15
    • 2016-12-10
    • 2021-11-05
    • 2011-02-21
    • 2017-02-15
    相关资源
    最近更新 更多