title: Upgraded to Springboot 2 AbstractRoutingDataSource not working
body: <p>Hi i was using Spring boot 1.4.0 it was working fine.</p>
  
  <p>When i upgraded to Spring boot 2.0.0 its giving below error.</p>
  
  <p>Could not open JDBC Connection for transaction; nested exception is java.lang.IllegalStateException: Cannot determine target DataSource for lookup key [null]</p>
  
  <p>at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:305)
      at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:378)
      at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:474)
      at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:289)
      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
      at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689)
      at com.vega.ui.service.SecurityServiceImpl$$EnhancerBySpringCGLIB$$5fdaff4b.getTenantIdByUserName()</p>
  
  <p>Here is my code to implement this</p>
  
  <p>public class TenantContext {
      private static ThreadLocal currentTenant = new ThreadLocal&lt;>();</p>
  
  <pre><code>public static void setCurrentTenant(Object tenant) {
      System.out.println("tenant : "+tenant);
      currentTenant.set(tenant);
  }
  
  public static Object getCurrentTenant() {
      return currentTenant.get();
  }
  
  public static void removeTenant() {
      currentTenant.remove();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>public class TenantRoutingDataSource extends AbstractRoutingDataSource {</p>
  
  <pre><code>String tenantId;
  
  private Map&lt;Object, Object&gt; mRountingTargetDataSources;
  
  
  
  
  public void setRountingTargetDataSources(Map&lt;Object, Object&gt; ptargetDataSources) {
      mRountingTargetDataSources = ptargetDataSources;
      this.setTargetDataSources(ptargetDataSources);
  }
  
  public Map&lt;Object, Object&gt; getRountingTargetDataSources() {
  
      return mRountingTargetDataSources;
  }
  
  @Override
  protected Object determineCurrentLookupKey() {
  
      if (TenantContext.getCurrentTenant() != null)
          return TenantContext.getCurrentTenant();
      else {
          return tenantId;
      }
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>@Bean(name = "transactionManager")
      @Autowired
      public DataSourceTransactionManager transactionManager(
              @Qualifier("dbTenantDataSource") TenantRoutingDataSource dataSource) {
          logger.info("Inside DataSourceTransactionManager");</p>
  
  <pre><code>    DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager(dataSource);
      dataSourceTransactionManager.setRollbackOnCommitFailure(true);
      return dataSourceTransactionManager;
  }
  </code></pre>