title: Spring Framework 5 and EhCache 3.5
body: <p>I tried to use EhCache 3.5 caching features in our web application based on Spring Boot 2/Spring Framework 5.</p>
  
  <p>I added EHCache dependency:</p>
  
  <pre><code>    &lt;dependency&gt;
          &lt;groupId&gt;org.ehcache&lt;/groupId&gt;
          &lt;artifactId&gt;ehcache&lt;/artifactId&gt;
          &lt;version&gt;3.5.0&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.cache&lt;/groupId&gt;
          &lt;artifactId&gt;cache-api&lt;/artifactId&gt;
          &lt;version&gt;1.0.0&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>Then created ehcache.xml file in src/main/resources folder:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true"
      monitoring="autodetect" dynamicConfig="true"&gt;
  
      &lt;cache name="orders" maxElementsInMemory="100" 
          eternal="false" overflowToDisk="false" 
          memoryStoreEvictionPolicy="LFU" copyOnRead="true"
          copyOnWrite="true" /&gt;
  &lt;/ehcache&gt;
  </code></pre>
  
  <p>Spring 5 reference guide does't mention EHCache usage, Spring 4 reference guide states: "Ehcache 3.x is fully JSR-107 compliant and no dedicated support is required for it."</p>
  
  <p>So I created controller OrderController and REST endpoint:</p>
  
  <pre><code>@Cacheable("orders")
  @GetMapping(path = "/{id}")
  public Order findById(@PathVariable int id) {
      return orderRepository.findById(id);
  }
  </code></pre>
  
  <p>Spring Boot configuration:</p>
  
  <pre><code>@SpringBootApplication
  @EnableCaching
  public class Application {
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);
      }
  }
  </code></pre>
  
  <p>But when I call this endpoint I get an exception:</p>
  
  <p>Cannot find cache named 'orders' for Builder[public org.Order org.OrderController.findById(int)] caches=[orders] | key='' | keyGenerator='' | cacheManager='' | cacheResolver='' | condition='' | unless='' | sync='false'</p>
  
  <p>Then I tried to use example from Spring Framework 4:</p>
  
  <pre><code>@Bean
  public CacheManager cacheManager() {
      return new EhCacheCacheManager(ehCacheCacheManager().getObject());
  }
  
  @Bean
  public EhCacheManagerFactoryBean ehCacheCacheManager() {
      EhCacheManagerFactoryBean cmfb = new EhCacheManagerFactoryBean();
      cmfb.setConfigLocation(new ClassPathResource("ehcache.xml"));
      cmfb.setShared(true);
      return cmfb;
  }
  </code></pre>
  
  <p>But it doesn't compile because of exception:</p>
  
  <p>The type net.sf.ehcache.CacheManager cannot be resolved. It is indirectly referenced from required .class file</p>
  
  <p>Please, advise.</p>