java - Spring Boot + Spring Data with multi tenancy -


is possible configure spring boot use multitenantconnectionprovider each client of system connects own private database?

specifically looking use built-in hibernate support multi-tenancy:

and example of sort of config after, can't figure out how use in spring boot setup:

i've tried adding these properties 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 

i've tried coding own currenttenantidentifierresolver , multitenantconnectionprovider , tried serving these main @configuration bean:

@bean public currenttenantidentifierresolver currenttenantidentifierresolver() {     return new currenttenantidentifierresolver() {         public string resolvecurrenttenantidentifier() {             // never called ...         }         public boolean validateexistingcurrentsessions() {             // never called ...         }     }; }  @bean public multitenantconnectionprovider multitenantconnectionprovider() {     return new abstractmultitenantconnectionprovider() {         protected connectionprovider getanyconnectionprovider() {             // never called ...         }         protected connectionprovider selectconnectionprovider(string s) {             // never called ...         }     }; } 

none of seems have affect question how spring-boot / spring-data use these multi-tenant classes?

thanks help!

any property jpa/hibernate isn't defined can set using spring.jpa.properties property in application.properties.

the sample link has 3 properties 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> 

that converted spring boot following properties in 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 situation (as stated in 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 

it not work spring manged beans hibernate controls lifecycle of instances.

for more properties see the spring boot reference guide.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -