title: Spring Cache With Couchbase Using LoadTimeWeaving - Strangely Not Working
body: <p>I'm adding Spring Cache on an existing spring project using annotations. I'm using Couchbase as cache provider. I want to use load time weaving using AspectJ to allow private method calls and case class method calls to be cached as well.</p>
  
  <p>It's been three days I'm stuck over this problem and I've read dozens of articles, documentations and examples but this thing just doesn't work.</p>
  
  <p>This is what I've done -</p>
  
  <pre><code>@Configuration
  @EnableSpringConfigured
  @EnableAspectJAutoProxy
  @EnableLoadTimeWeaving(aspectjWeaving = EnableLoadTimeWeaving.AspectJWeaving.ENABLED)
  @EnableTransactionManagement
  @EnableRetry
  @PropertySource(
          value = {"classpath:application.properties", "classpath:${spring.profiles.active}.properties"},
          ignoreResourceNotFound = true)
  public class BeanConfig implements LoadTimeWeavingConfigurer {
  
      ... various beans here ...
  
      @Override
      public LoadTimeWeaver getLoadTimeWeaver() {
          return new TomcatLoadTimeWeaver();// because I'm using Tomcat 7
      }
  
      @Bean
      public InstrumentationLoadTimeWeaver loadTimeWeaver()  throws Throwable {
          return new InstrumentationLoadTimeWeaver();
      }
  }
  
  @Configuration
  @EnableSpringConfigured
  @EnableCaching(mode = AdviceMode.ASPECTJ)
  @ComponentScan(basePackages = "com.foo.bar.dao.cache.couchbase")
  public class CacheConfigurer extends CachingConfigurerSupport {
      @Bean
      @Override
      public CacheManager cacheManager() {
          ... cachemanager configuration here ...
      }
  }
  </code></pre>
  
  <p>Then I have <code>@Chacheable</code> on a DAO method  on class, not on interface.</p>
  
  <p>Finally, in my Tomcat 7's $CATALINA_HOME/conf/context.xml I have -</p>
  
  <pre><code>&lt;Context&gt;
      &lt;Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/&gt;    
  &lt;/Context&gt;
  </code></pre>
  
  <p>I have added following dependencies in pom.xml (its a maven project) -</p>
  
  <ul>
  <li>couchbase-spring-cache</li>
  <li>spring-aspects</li>
  <li>aspectjweaver</li>
  <li>aspectjrt</li>
  <li>spring-instrument </li>
  <li>spring-instrument-tomcat</li>
  </ul>
  
  <p>If I do not use LTW caching works fine for methods calls arriving through interfaces (as it should). But after I enable LTW caching doesn't works at all - no caching for any method call, no errors either. </p>
  
  <p>Has anyone tried using LTW for Spring cache with couchbase? What am I missing or doing wrong here?</p>
  
  <p>I'm on Spring 4.3.5.Release.</p>
  
  <p><strong>Update -</strong></p>
  
  <p>Here is my bare-minimal code replicating the situation - <a href="https://github.com/harshilsharma63/spring-boilerplate-with-cache" rel="nofollow noreferrer">https://github.com/harshilsharma63/spring-boilerplate-with-cache</a></p>