【发布时间】:2018-12-29 14:54:16
【问题描述】:
我有一个在 MySQL 数据库上运行的多租户 Spring Boot 应用程序,为各个租户提供单独的架构。 dataSource 是通过在运行时传递标头代码来决定的。如何确保连接不会在这样的系统中掉线?一旦系统的不活动时间超过了设定的时间,“SELECT 1”命令就需要运行,并且没有向系统指定要连接的数据源的任何内容,因此系统会抛出 sql 异常。
这是我的配置属性:
spring.datasource.url=jdbc:mysql://xxxxxxxx/xxx?useUnicode=true&characterEncoding=utf8&useSSL=false&autoReconnect=true spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL57InnoDBDialect spring.jpa.database=MYSQL spring.jpa.hibernate.ddl-auto=验证 spring.datasource.test-on-borrow=true spring.datasource.testWhileIdle = true spring.datasource.timeBetweenEvictionRunsMillis = 60000 spring.datasource.validation-query=SELECT 1 spring.datasource.tomcat.max-wait=10000 spring.datasource.tomcat.max-active=50 spring.datasource.tomcat.test-on-borrow=true spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate4.SpringSessionContext hibernate.c3p0.max_size=20 hibernate.c3p0.min_size=5 hibernate.c3p0.idle_test_period=600
【问题讨论】:
-
希望我能看到你的配置文件。 1.检查配置文件中的超时,理想时间属性。 2. 解决方法 当新查询出现时,它应该先尝试建立连接,然后执行查询,但理想情况下,有一个正确配置的连接池可以在我们的生产服务器中工作。
标签: java spring connection