title: How to configure Caffeine Cache with Spring
body: <p>I have a simple Spring application. I need to implement caching onto a few services that are expensive to call each time.</p>
  <p>I have a configuration class like this:</p>
  <pre><code>@Configuration
  @EnableCaching
  public class CachingConfig {
  
  @Bean (name = &quot;caffeineCacheManager&quot;)
  public CacheManager cacheManager() {
      CaffeineCacheManager cacheManager = new CaffeineCacheManager(&quot;projectList&quot;, &quot;backlog&quot;, &quot;childProjectList&quot;, &quot;testRun&quot;);
      cacheManager.setCaffeine(caffeineCacheBuilder());
      return cacheManager;
  }
  
  Caffeine&lt; Object, Object &gt; caffeineCacheBuilder() {
      return Caffeine.newBuilder()
              .initialCapacity(100)
              .maximumSize(500)
              .expireAfterAccess(1, TimeUnit.MINUTES)
              .weakKeys()
              .recordStats();
  }
  }
  </code></pre>
  <p>My <code>pom.xml</code> includes :</p>
  <pre><code>&lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-context-support&lt;/artifactId&gt;
          &lt;version&gt;5.2.8.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.github.ben-manes.caffeine&lt;/groupId&gt;
          &lt;artifactId&gt;caffeine&lt;/artifactId&gt;
          &lt;version&gt;2.8.8&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>
  <p>I have one of the method that needs to be cached like this:</p>
  <pre><code>@Cacheable(value = &quot;projectList&quot;, cacheManager = &quot;caffeineCacheManager&quot;)
  public Map&lt;String, String&gt; getProjectList() {
      return getProjectList(); //**SOME EXPENSIVE CALL**
  }
  </code></pre>
  <p>Everytime I run the app I get <code>java.lang.NoClassDefFoundError: com/github/benmanes/caffeine/cache/Caffeine</code>.</p>
  <p>Here is the complete stack trace : <a href="https://textuploader.com/1eil3" rel="nofollow noreferrer">https://textuploader.com/1eil3</a>
  I am not sure where am I doing wrong or If I am missing something.</p>