1. <tfoot id='Putyw'></tfoot>
      <i id='Putyw'><tr id='Putyw'><dt id='Putyw'><q id='Putyw'><span id='Putyw'><b id='Putyw'><form id='Putyw'><ins id='Putyw'></ins><ul id='Putyw'></ul><sub id='Putyw'></sub></form><legend id='Putyw'></legend><bdo id='Putyw'><pre id='Putyw'><center id='Putyw'></center></pre></bdo></b><th id='Putyw'></th></span></q></dt></tr></i><div id='Putyw'><tfoot id='Putyw'></tfoot><dl id='Putyw'><fieldset id='Putyw'></fieldset></dl></div>

    2. <legend id='Putyw'><style id='Putyw'><dir id='Putyw'><q id='Putyw'></q></dir></style></legend>

      <small id='Putyw'></small><noframes id='Putyw'>

        • <bdo id='Putyw'></bdo><ul id='Putyw'></ul>

        Spring Boot + Spring Data 多租户

        Spring Boot + Spring Data with multi tenancy(Spring Boot + Spring Data 多租户)
        • <small id='ZkUCk'></small><noframes id='ZkUCk'>

          <i id='ZkUCk'><tr id='ZkUCk'><dt id='ZkUCk'><q id='ZkUCk'><span id='ZkUCk'><b id='ZkUCk'><form id='ZkUCk'><ins id='ZkUCk'></ins><ul id='ZkUCk'></ul><sub id='ZkUCk'></sub></form><legend id='ZkUCk'></legend><bdo id='ZkUCk'><pre id='ZkUCk'><center id='ZkUCk'></center></pre></bdo></b><th id='ZkUCk'></th></span></q></dt></tr></i><div id='ZkUCk'><tfoot id='ZkUCk'></tfoot><dl id='ZkUCk'><fieldset id='ZkUCk'></fieldset></dl></div>
          <tfoot id='ZkUCk'></tfoot>
            <tbody id='ZkUCk'></tbody>
          • <bdo id='ZkUCk'></bdo><ul id='ZkUCk'></ul>
              <legend id='ZkUCk'><style id='ZkUCk'><dir id='ZkUCk'><q id='ZkUCk'></q></dir></style></legend>

                  本文介绍了Spring Boot + Spring Data 多租户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  是否可以将 Spring Boot 配置为使用 MultiTenantConnectionProvider 以便我系统的每个客户端都连接到自己的私有数据库?

                  Is it possible to configure Spring Boot to use a MultiTenantConnectionProvider so that each client of my system connects to their own private database?

                  具体来说,我希望使用内置的休眠支持来支持多租户:

                  Specifically I am looking to use the built-in hibernate support for multi-tenancy:

                  • http://docs.jboss.org/hibernate/orm/4.1/devguide/en-US/html_single/#d5e4561

                  这是我所追求的那种配置的一个例子,但我不知道如何在 Spring Boot 设置中使用它:

                  And this is an example of the sort of config I am after, but I can't figure out how to use this in a Spring Boot setup:

                  • 管理连接池在带有 Spring、Hibernate 和 C3P0 的多租户 Web 应用中

                  我尝试将这些属性添加到 application.properties:

                  I've tried adding these properties to application.properties:

                  spring.jpa.hibernate.multiTenancy=DATABASE
                  spring.jpa.hibernate.tenant_identifier_resolver=com.mystuff.MyCurrentTenantIdentifierResolver
                  spring.jpa.hibernate.multi_tenant_connection_provider=com.mystuff.MyMultiTenantConnectionProviderImplX
                  

                  我也尝试编写自己的 CurrentTenantIdentifierResolverMultiTenantConnectionProvider 并尝试从我的主 @Configuration bean 提供这些:

                  I've also tried coding up my own CurrentTenantIdentifierResolver and MultiTenantConnectionProvider and tried serving these up from my main @Configuration bean:

                  @Bean
                  public CurrentTenantIdentifierResolver currentTenantIdentifierResolver() {
                      return new CurrentTenantIdentifierResolver() {
                          public String resolveCurrentTenantIdentifier() {
                              // this is never called ...
                          }
                          public boolean validateExistingCurrentSessions() {
                              // this is never called ...
                          }
                      };
                  }
                  
                  @Bean
                  public MultiTenantConnectionProvider multiTenantConnectionProvider() {
                      return new AbstractMultiTenantConnectionProvider() {
                          protected ConnectionProvider getAnyConnectionProvider() {
                              // this is never called ...
                          }
                          protected ConnectionProvider selectConnectionProvider(String s) {
                              // this is never called ...
                          }
                      };
                  }
                  

                  这些似乎都没有任何影响,所以我的问题是如何让 spring-boot/spring-data 使用这些多租户类?

                  None of this seems to have any affect so my question is really how to get spring-boot / spring-data to use these multi-tenant classes?

                  感谢您的帮助!

                  推荐答案

                  任何未定义的 JPA/Hibernate 属性 都可以使用 spring.jpa.properties 进行设置application.properties 中的 属性.

                  Any property for JPA/Hibernate that isn't defined can be set using the spring.jpa.properties property in the application.properties.

                  您链接到的示例具有 3 个多租户属性:

                  The sample you link to has 3 properties for multitenancy:

                  <prop key="hibernate.multiTenancy">SCHEMA</prop>
                  <prop key="hibernate.tenant_identifier_resolver">com.webapp.persistence.utility.CurrentTenantContextIdentifierResolver</prop>
                  <prop key="hibernate.multi_tenant_connection_provider">com.webapp.persistence.utility.MultiTenantContextConnectionProvider</prop>
                  

                  转换为 Spring Boot 的将是 application.properties 文件中的以下属性.

                  That converted to Spring Boot would be the following properties in the application.properties file.

                  spring.jpa.properties.hibernate.multiTenancy=SCHEMA
                  spring.jpa.properties.hibernate.tenant_identifier_resolver=com.mystuff.MyCurrentTenantIdentifierResolver
                  spring.jpa.properties.hibernate.multi_tenant_connection_provider=com.webapp.persistence.utility.MultiTenantContextConnectionProvider
                  

                  针对您的情况(如您的问题所述).

                  For your situation (as stated in your question).

                  spring.jpa.properties.hibernate.multiTenancy=DATABASE
                  spring.jpa.properties.hibernate.tenant_identifier_resolver=com.webapp.persistence.utility.CurrentTenantContextIdentifierResolver 
                  spring.jpa.properties.hibernate.multi_tenant_connection_provider=com.mystuff.MyMultiTenantConnectionProviderImplX
                  

                  它不适用于 Spring 管理的 bean,因为休眠控制这些实例的生命周期.

                  It will not work with Spring manged beans as hibernate controls the lifecycle of those instances.

                  有关更多属性,请参阅 Spring Boot 参考指南.

                  For more properties see the the Spring Boot reference guide.

                  这篇关于Spring Boot + Spring Data 多租户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)

                  <small id='HHNpC'></small><noframes id='HHNpC'>

                        <bdo id='HHNpC'></bdo><ul id='HHNpC'></ul>
                          <tbody id='HHNpC'></tbody>
                        <legend id='HHNpC'><style id='HHNpC'><dir id='HHNpC'><q id='HHNpC'></q></dir></style></legend>

                        • <i id='HHNpC'><tr id='HHNpC'><dt id='HHNpC'><q id='HHNpC'><span id='HHNpC'><b id='HHNpC'><form id='HHNpC'><ins id='HHNpC'></ins><ul id='HHNpC'></ul><sub id='HHNpC'></sub></form><legend id='HHNpC'></legend><bdo id='HHNpC'><pre id='HHNpC'><center id='HHNpC'></center></pre></bdo></b><th id='HHNpC'></th></span></q></dt></tr></i><div id='HHNpC'><tfoot id='HHNpC'></tfoot><dl id='HHNpC'><fieldset id='HHNpC'></fieldset></dl></div>
                        • <tfoot id='HHNpC'></tfoot>