title: Exceptions while running spring boot code with distributed terracotta ehcache
body: <p>i have created a spring boot project which uses distributed ehcache. I downloaded and run terracotta server with configuration in tc-config.xml. Servers are running successfully on localhost:9510. following is my ehcache.xml which is in classpath of spring boot project</p>
  
  <pre><code>&lt;ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:noNamespaceSchemaLocation="ehcache.xsd"&gt;
      &lt;terracottaConfig url="localhost:9510"/&gt;
      &lt;cache name="ticketsCache" maxEntriesLocalHeap="1000"&gt;
          &lt;terracotta consistency="eventual"/&gt;
      &lt;/cache&gt;
  &lt;/ehcache&gt;
  </code></pre>
  
  <p>Following is my maven dependencies.</p>
  
  <pre><code>&lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;1.5.6.RELEASE&lt;/version&gt;
          &lt;relativePath /&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-cache&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;!-- &lt;dependency&gt;
              &lt;groupId&gt;net.sf.ehcache&lt;/groupId&gt;
              &lt;artifactId&gt;ehcache&lt;/artifactId&gt;
          &lt;/dependency&gt; --&gt;
  
          &lt;!-- https://mvnrepository.com/artifact/org.ehcache/ehcache-clustered --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.ehcache&lt;/groupId&gt;
              &lt;artifactId&gt;ehcache-clustered&lt;/artifactId&gt;
  
          &lt;/dependency&gt;
              &lt;!-- https://mvnrepository.com/artifact/net.sf.ehcache/ehcache-core --&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;net.sf.ehcache&lt;/groupId&gt;
      &lt;artifactId&gt;ehcache-core&lt;/artifactId&gt;
     &lt;version&gt;2.6.5&lt;/version&gt;
  &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;!-- https://mvnrepository.com/artifact/net.sf.ehcache/ehcache-terracotta --&gt;
          &lt;!-- https://mvnrepository.com/artifact/net.sf.ehcache/ehcache-core --&gt;
  
          &lt;!-- https://mvnrepository.com/artifact/net.sf.ehcache/ehcache-core --&gt;
          &lt;!-- &lt;dependency&gt; &lt;groupId&gt;net.sf.ehcache&lt;/groupId&gt; &lt;artifactId&gt;ehcache-core&lt;/artifactId&gt; 
              &lt;version&gt;2.6.6&lt;/version&gt; &lt;/dependency&gt; --&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;net.sf.ehcache&lt;/groupId&gt;
              &lt;artifactId&gt;ehcache&lt;/artifactId&gt;
  
          &lt;/dependency&gt;
  
  
  
          &lt;!-- &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt; --&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.terracotta&lt;/groupId&gt;
              &lt;artifactId&gt;terracotta-toolkit-runtime-ee&lt;/artifactId&gt;
              &lt;version&gt;4.0.0&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-ehcache --&gt;
  
      &lt;!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-ehcache --&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
      &lt;artifactId&gt;hibernate-ehcache&lt;/artifactId&gt;
      &lt;version&gt;3.3.2.GA&lt;/version&gt;
  &lt;/dependency&gt;
      &lt;!-- https://mvnrepository.com/artifact/javax.cache/cache-api --&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-PFD&lt;/version&gt;
  &lt;/dependency&gt;
  
  
      &lt;/dependencies&gt;
  
      &lt;repositories&gt;
          &lt;repository&gt;
              &lt;id&gt;terracotta-releases&lt;/id&gt;
              &lt;url&gt;http://www.terracotta.org/download/reflector/releases/&lt;/url&gt;
          &lt;/repository&gt;
      &lt;/repositories&gt;
  
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  </code></pre>
  
  <p>Following is my code in which i am trying to create a cache manager so that it can be used in my application</p>
  
  <pre><code>import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  import org.springframework.cache.CacheManager;
  import org.springframework.cache.annotation.EnableCaching;
  import org.springframework.cache.ehcache.EhCacheCacheManager;
  import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
  import org.springframework.context.annotation.Bean;
  import org.springframework.core.io.ClassPathResource;
  
  @SpringBootApplication
  @EnableCaching
  public class TicketBookingManagementApplication {
  
      public TicketBookingManagementApplication() {
  
      }
      @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;
          }
      public static void main(String[] args) {
          SpringApplication.run(TicketBookingManagementApplication.class, args);
      }
  
  }
  </code></pre>
  
  <p>But i am getting exceptions as below</p>
  
  <pre><code>cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheManager' defined in com.infotech.book.ticket.app.TicketBookingManagementApplication: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cache.CacheManager]: Factory method 'cacheManager' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehCacheCacheManager' defined in com.infotech.book.ticket.app.TicketBookingManagementApplication: Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: java.lang.NoClassDefFoundError: net/sf/ehcache/config/TerracottaConfigConfiguration
  2018-01-10 14:57:25.675  INFO 27288 --- [           main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
  2018-01-10 14:57:25.683  INFO 27288 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
  2018-01-10 14:57:25.701  INFO 27288 --- [           main] utoConfigurationReportLoggingInitializer : 
  
  Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
  2018-01-10 14:57:25.713 ERROR 27288 --- [           main] o.s.boot.SpringApplication               : Application startup failed
  
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheManager' defined in com.infotech.book.ticket.app.TicketBookingManagementApplication: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cache.CacheManager]: Factory method 'cacheManager' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehCacheCacheManager' defined in com.infotech.book.ticket.app.TicketBookingManagementApplication: Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: java.lang.NoClassDefFoundError: net/sf/ehcache/config/TerracottaConfigConfiguration
      at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
      at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
      at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
      at com.infotech.book.ticket.app.TicketBookingManagementApplication.main(TicketBookingManagementApplication.java:32) [classes/:na]
  Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cache.CacheManager]: Factory method 'cacheManager' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehCacheCacheManager' defined in com.infotech.book.ticket.app.TicketBookingManagementApplication: Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: java.lang.NoClassDefFoundError: net/sf/ehcache/config/TerracottaConfigConfiguration
      at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      ... 18 common frames omitted
  Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehCacheCacheManager' defined in com.infotech.book.ticket.app.TicketBookingManagementApplication: Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: java.lang.NoClassDefFoundError: net/sf/ehcache/config/TerracottaConfigConfiguration
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:334) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at com.infotech.book.ticket.app.TicketBookingManagementApplication$$EnhancerBySpringCGLIB$$fdf56fc4.ehCacheCacheManager(&lt;generated&gt;) ~[classes/:na]
      at com.infotech.book.ticket.app.TicketBookingManagementApplication.cacheManager(TicketBookingManagementApplication.java:22) [classes/:na]
      at com.infotech.book.ticket.app.TicketBookingManagementApplication$$EnhancerBySpringCGLIB$$fdf56fc4.CGLIB$cacheManager$0(&lt;generated&gt;) ~[classes/:na]
      at com.infotech.book.ticket.app.TicketBookingManagementApplication$$EnhancerBySpringCGLIB$$fdf56fc4$$FastClassBySpringCGLIB$$af6a5740.invoke(&lt;generated&gt;) ~[classes/:na]
      at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at com.infotech.book.ticket.app.TicketBookingManagementApplication$$EnhancerBySpringCGLIB$$fdf56fc4.cacheManager(&lt;generated&gt;) ~[classes/:na]
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_131]
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_131]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_131]
      at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_131]
      at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      ... 19 common frames omitted
  Caused by: net.sf.ehcache.CacheException: java.lang.NoClassDefFoundError: net/sf/ehcache/config/TerracottaConfigConfiguration
      at net.sf.ehcache.CacheManager.init(CacheManager.java:401) ~[ehcache-core-2.6.5.jar:na]
      at net.sf.ehcache.CacheManager.&lt;init&gt;(CacheManager.java:259) ~[ehcache-core-2.6.5.jar:na]
      at net.sf.ehcache.CacheManager.newInstance(CacheManager.java:1037) ~[ehcache-core-2.6.5.jar:na]
      at net.sf.ehcache.CacheManager.newInstance(CacheManager.java:1013) ~[ehcache-core-2.6.5.jar:na]
      at net.sf.ehcache.CacheManager.create(CacheManager.java:998) ~[ehcache-core-2.6.5.jar:na]
      at org.springframework.cache.ehcache.EhCacheManagerFactoryBean.afterPropertiesSet(EhCacheManagerFactoryBean.java:144) ~[spring-context-support-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
      ... 38 common frames omitted
  Caused by: java.lang.NoClassDefFoundError: net/sf/ehcache/config/TerracottaConfigConfiguration
      at java.lang.Class.getDeclaredConstructors0(Native Method) ~[na:1.8.0_131]
      at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671) ~[na:1.8.0_131]
      at java.lang.Class.getConstructor0(Class.java:3075) ~[na:1.8.0_131]
      at java.lang.Class.getConstructor(Class.java:1825) ~[na:1.8.0_131]
      at net.sf.ehcache.util.ClassLoaderUtil.createNewInstance(ClassLoaderUtil.java:91) ~[ehcache-core-2.6.5.jar:na]
      at net.sf.ehcache.terracotta.TerracottaClusteredInstanceHelper.newClusteredInstanceFactory(TerracottaClusteredInstanceHelper.java:176) ~[ehcache-core-2.6.5.jar:na]
      at net.sf.ehcache.terracotta.TerracottaClient.createNewClusteredInstanceFactory(TerracottaClient.java:186) ~[ehcache-core-2.6.5.jar:na]
      at net.sf.ehcache.terracotta.TerracottaClient.createClusteredInstanceFactory(TerracottaClient.java:138) ~[ehcache-core-2.6.5.jar:na]
      at net.sf.ehcache.CacheManager.doInit(CacheManager.java:432) ~[ehcache-core-2.6.5.jar:na]
      at net.sf.ehcache.CacheManager.init(CacheManager.java:377) ~[ehcache-core-2.6.5.jar:na]
      ... 45 common frames omitted
  Caused by: java.lang.ClassNotFoundException: net.sf.ehcache.config.TerracottaConfigConfiguration
      at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_131]
      at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_131]
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) ~[na:1.8.0_131]
      at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_131]
      ... 55 common frames omitted
  </code></pre>
  
  <p>Any help would be appreciated</p>