MongoTemplate in MultiTenant Spring Data Mongo Application -


this follow question making spring-data-mongodb multi-tenant oliver gierke explained options how set-up multi-tenancy springdatamongo application. followed "collection approach" , quite successful. far. problems arise, when want customise mongotemplate used. have on example:

@springbootapplication public class multitenantmongoapplication {      public static void main(string[] args) {         springapplication.run(multitenantmongoapplication.class, args);     }      @bean     public mongotemplate mongotemplate(mongo mongo, @value("${random.name}") string randomname) throws exception {         string dbname = "db_" + randomname;         mongotemplate mongotemplate = new mongotemplate(mongo, dbname) {             @suppresswarnings("unused")             public void shutdown() {                 mongo.dropdatabase(dbname);             }         };         return mongotemplate;     } }  @document(collection="#{tenantprovider.gettenantcollectionname('metric')}") public class metric {  }  @repository public interface metricrepository extends mongorepository<metric, objectid>{}  @component public class tenantprovider {     public string gettenantcollectionname(string collectionname) {         ...     } } 

this yields following error:

spelevaluationexception: el1007e: property or field 'tenantprovider' cannot found on null

when remove definition of mongotemplate bean in application class fine , runs desired. property provider gets not configured appropriately, when mongotemplate customised. why happening? , can do, property in place?

i think above error because of spel expression. can try way access tenantprovider class using below spel expression.

#{t(tenantprovider).gettenantcollectionname('metric')} 

or can add qualified class name tenantprovider in above expression.


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -