Skip to main content

Ehcache: deploy multiple versions of a Grails app (fix javax.management.InstanceAlreadyExistsException)

When a Grails application makes use of the Ehcache cache plugin in its default configuration it can be impossibile to perform deploys of multiple versions of the app, even though the container might support it.
The same plugin (in its default configuration) also breaks deploying multiple different Grails apps on the same container.

The problem is in the way the plugin generates the name for the cache (which will then be used to register the cache jmx bean): the name is by default set grails-cache-ehcache. When another second application or another application version is deployed registration will fail because the name already exists. The exception message is the following (indented for clarity):

org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'ehCacheManagementService':
Invocation of init method failed;
nested exception is net.sf.ehcache.CacheException:
javax.management.InstanceAlreadyExistsException:
net.sf.ehcache:type=CacheManager,name=grails-cache-ehcache

The (undocumented) solution is easy to implement. Edit the Config.groovy file and add the following configuration bit:

grails.cache.config = {
  provider {
    name "ehcache-<yourappname>-"+(new Date().format("yyyyMMddHHmmss"))
  }
}

If you are using the ehcache.xml file instead it might be more difficult to randomize the cache name, but it could be done during the build.

Tested on Grails 2.1.5 and Tomcat 7.

Comments

Popular posts from this blog

Indexing Apache access logs with ELK (Elasticsearch+Logstash+Kibana)

Who said that grepping Apache logs has to be boring?

The truth is that, as Enteprise applications move to the browser too, Apache access logs are a gold mine, it does not matter what your role is: developer, support or sysadmin. If you are not mining them you are most likely missing out a ton of information and, probably, making the wrong decisions.
ELK (Elasticsearch, Logstash, Kibana) is a terrific, Open Source stack for visually analyzing Apache (or nginx) logs (but also any other timestamped data).

From 0 to ZFS replication in 5m with syncoid

The ZFS filesystem has many features that once you try them you can never go back. One of the lesser known is probably the support for replicating a zfs filesystem by sending the changes over the network with zfs send/receive.
Technically the filesystem changes don't even need to be sent over a network: you could as well dump them on a removable disk, then receive  from the same removable disk.

A not so short guide to TDD SaltStack formulas

One of the hardest parts about Infrastructure As Code and Configuration Management is establishing a discipline on developing, testing and deploying changes.
Developers follow established practices and tools have been built and perfected over the last decade and a half. On the other hand sysadmins and ops people do not have the same tooling and culture because estensive automation has only become a trend recently.

So if Infrastructure As Code allows you to version the infrastructure your code runs on, what good is it if then there are no tools or established practices to follow?

Luckily the situation is changing and in this post I'm outlining a methodology for test driven development of SaltStack Formulas.

The idea is that with a single command you can run your formula against a matrix of platforms (operating systems) and suites (or configurations). Each cell of the matrix will be tested and the result is a build failure or success much alike to what every half-decent developer of…