我在MySQL数据库上运行了一个多租户spring引导应用程序,为各个租户提供了单独的模式。dataSource是通过在运行时传递一个头代码来决定的。如何确保连接不掉在这样的系统中?一旦系统的不活动超过了设定的时间,"SELECT 1“命令就需要运行,这不会向dataSource连接的系统指定任何内容,因此系统会抛出SELECT。
下面是我的配置属性:
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=验证SELECT.Dataource.test-on-借用= true spring.datasource.testWhileIdle =true spring.datasource.timeBetweenEvictionRunsMillis =true spring.datasource.timeBetweenEvictionRunsMillis= 60000 SELECT.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
发布于 2018-09-17 12:35:21
我发现,一旦我们有了application.properties设置,在hibernate.multiTenancy=DATABASE文件中指定的数据源验证查询设置就不会产生任何效果,因为我们需要拦截getConnection调用并以编程方式解析“数据源”租户。因此,我使用扩展的CustomMultiTenantConnectionProviderImpl来解决这个问题,它实现了MultiTenantConnectionProvider接口,并覆盖了getConnection和releaseConnection方法的定义,以完成需要完成的任务。现在我的连接被正确地验证了。
https://stackoverflow.com/questions/51457029
复制相似问题