Pergunta

I'm using the play default cache in my application. When I try running my play 2.1 application using the target/start command on a server I get this error message:

net.sf.ehcache.CacheException: Caches cannot be added by name when default cache config is not specified in the config. Please add a default cache config in the configuration.

Works fine in dev mode. Is there somewhere I need to specify a default cache?

Foi útil?

Solução

Your stack trace indicates that the exception is being thrown from Play Framework code that tries to programmatically create a cache called "play". As the EhCache documentation explains:

When you try to programmatically add a cache by name, CacheManager.add(String name), a default cache is expected to exist in the CacheManager configuration. To fix this error, add a defaultCache to the CacheManager's configuration.

The fix is simple enough - make sure the ehcache.xml file you are using has a defaultcache element (you can see what a defaultcache element looks like in Play 2.1's default Ehcache configuration). The key question that still needs addressing is which configuration file is being used when you start up your application:

  • If you've included an ehcache.xml file in the conf directory in your application, make sure it has a defaultcache element. Alternatively, if you don't have any of your own custom configuration in this file, you can considering deleting it and falling back to using Play's default configuration.

  • If you don't have your own ehcache.xml file, search over the JAR files in your staged directory and see if any contain an ehcache.xml file.

As for why the error happens in some circumstances and not others, I would venture that there are classpath ordering differences between the various commands. This means that some commands will choose Play's internal Ehcache configuration (with the server then starting up cleanly), whereas others will load an incorrect Ehcache configuration file and spew out errors.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top