spring - MultiTenantConnectionProvider implementation has null autowired datasource -
i'm trying support multi-tenant schema in spring boot (1.4) application. have following in config:
hibernate: format_sql: true default_schema: corrto multitenancy: schema tenant_identifier_resolver: com.config.headertenantidentifierresolver multi_tenant_connection_provider: com.config.schemapertenantconnectionprovider
my multitenantconnectionprovider implementation follows:
public class schemapertenantconnectionprovider implements multitenantconnectionprovider { @autowired private datasource datasource; @override public connection getanyconnection() throws sqlexception { return this.datasource.getconnection(); } @override public void releaseanyconnection(connection connection) throws sqlexception { connection.close(); } @override public connection getconnection(string tenantidentifier) throws sqlexception { final connection connection = this.getanyconnection(); // need stuff here return connection; } @override public void releaseconnection(string tenantidentifier, connection connection) throws sqlexception { } @override public boolean supportsaggressiverelease() { return true; } @override public boolean isunwrappableas(class unwraptype) { return false; } @override public <t> t unwrap(class<t> unwraptype) { return null; } }
it failing because datasource
null. i'm assuming hasn't been created yet i'm having hard time finding solutions via google.
i met same problem.it seems in yml
,headertenantidentifierresolver
, schemapertenantconnectionprovider
managed hibernate.see here.
Comments
Post a Comment