Question

Created empty grails project

grails create-app foo

Modified BuildConfig.groovy, uncommented

inherits("global") {  
  // uncomment to disable ehcache                                                                                                                                                                                                        
  excludes 'ehcache'                                                                                                                                                                                                                       
}  

So now ehcache is excluded.

Copied these 5 jars from terracotta installation to foo/lib directory:

ehcache-core-ee-2.6.2.jar
ehcache-terracotta-ee-2.6.2.jar
slf4j-api-1.6.1.jar
slf4j-jdk14-1.6.1.jar
terracotta-toolkit-1.6-runtime-ee-5.2.0.jar

Created ehcache.xml in grails-app/conf/ directory:

<ehcache>

  <terracottaConfig url="vm4:9510"/>

   <defaultCache
       maxElementsInMemory="50"
       eternal="false"
       timeToIdleSeconds="20"
       timeToLiveSeconds="20"
       overflowToDisk="false"
       diskPersistent="false"
       memoryStoreEvictionPolicy="LRU">

    <terracotta clustered="true" valueMode="serialization"/>
  </defaultCache>

</ehcache>

Running project through grails run-app and getting this exception:

Message: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'transactionManager': 
Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.cache.CacheException: 
net.sf.ehcache.CacheException: Could not create ClusteredInstanceFactory due to missing class. Please verify that terracotta-toolkit is in your classpath.
Was it helpful?

Solution

Remove all the jars from foo/lib directory, and insert some dependencies into BuildConfig.groovy:

    repositories {
        .....
        mavenRepo "http://www.terracotta.org/download/reflector/releases"
    }
    dependencies {
        runtime 'net.sf.ehcache:ehcache-core:2.6.2'
        runtime 'net.sf.ehcache:ehcache-terracotta:2.6.2'
        runtime 'org.terracotta:terracotta-toolkit-1.6-runtime:5.2.0'
    }

That will enable automatic download of other necessary jars from the repo and classpath setup.

And, if you setup a open source terracotta server like I did, the enterprise edition foo/lib/ehcache-terracotta-ee-2.6.2.jar will cause an error:

ERROR - An Enterprise client can not connect to an Opensource Server, Connection refused.

The key part:

Run the app with grails -noreloading run-app instead of grails run-app to bypass the reloading agent. Then the distributed cache app should be working.

p.s. Deploying the app to production requires no extra work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top