title: mongodb multi tenacy spel with @Document
body: <p>This is related to 
  <a href="https://stackoverflow.com/questions/18129291/mongodb-and-spel-expressions-in-document-annotations">MongoDB and SpEL Expressions in @Document annotations</a></p>
  
  <p>This is the way I am creating my mongo template</p>
  
  <pre><code>@Bean
  public MongoDbFactory mongoDbFactory() throws UnknownHostException {
      String dbname = getCustid();
      return new SimpleMongoDbFactory(new MongoClient("localhost"), "mydb");
  }
  
  @Bean
  MongoTemplate mongoTemplate() throws UnknownHostException {
      MappingMongoConverter converter = 
              new MappingMongoConverter(mongoDbFactory(), new MongoMappingContext());
      return new MongoTemplate(mongoDbFactory(), converter);
  }
  </code></pre>
  
  <p>I have a tenant provider class</p>
  
  <pre><code>@Component("tenantProvider")
  public class TenantProvider {
  
      public String getTenantId() {
        --custome Thread local logic for getting a name
      }
  }
  </code></pre>
  
  <p>And my domain class</p>
  
  <pre><code>    @Document(collection = "#{@tenantProvider.getTenantId()}_device")
       public class Device {
      -- my fields here
      }
  </code></pre>
  
  <p>As you see I have created my mongotemplate as specified in the post, but I still get the below error</p>
  
  <blockquote>
    <p>Exception in thread "main" org.springframework.expression.spel.SpelEvaluationException: EL1057E:(pos 1): No bean resolver registered in the context to resolve access to bean 'tenantProvider'</p>
  </blockquote>
  
  <p>What am I doing wrong?</p>