首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >多租户系统的Spring验证-查询

问多租户系统的Spring验证-查询
EN

Stack Overflow用户
提问于 2018-07-21 14:35:25
回答 1查看 543关注 0票数 0

我在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

EN

回答 1

Stack Overflow用户

发布于 2018-09-17 12:35:21

我发现,一旦我们有了application.properties设置,在hibernate.multiTenancy=DATABASE文件中指定的数据源验证查询设置就不会产生任何效果,因为我们需要拦截getConnection调用并以编程方式解析“数据源”租户。因此,我使用扩展的CustomMultiTenantConnectionProviderImpl来解决这个问题,它实现了MultiTenantConnectionProvider接口,并覆盖了getConnection和releaseConnection方法的定义,以完成需要完成的任务。现在我的连接被正确地验证了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51457029

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档