Play Framework:EhCache问题在每个代码热编译

时间:2016-08-19 05:44:30

标签: scala caching playframework

在Play 2.5.3中,使用Scala:

我使用缓存作为模块,每次更改代码然后刷新浏览器,重新编译后我都会遇到以下问题:

[TechnicalException: com.google.inject.ProvisionException: Unable to provision, see the following errors:

1) Error in custom provider, play.api.cache.EhCacheExistsException: An EhCache instance with name 'play' already exists.

This usually indicates that multiple instances of a dependent component (e.g. a Play application) have been started at the same time.

  at play.api.cache.EhCacheModule.play$api$cache$EhCacheModule$$bindCache$1(Cache.scala:184):
Binding(interface net.sf.ehcache.Ehcache qualified with QualifierInstance(@play.cache.NamedCache(value=play)) to ProviderTarget(play.api.cache.NamedEhCacheProvider@2dfe19e7)) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1)
  while locating net.sf.ehcache.Ehcache annotated with @play.cache.NamedCache(value=play)
  at play.api.cache.EhCacheModule.play$api$cache$EhCacheModule$$bindCache$1(Cache.scala:185):
Binding(interface play.api.cache.CacheApi qualified with QualifierInstance(@play.cache.NamedCache(value=play)) to ProviderTarget(play.api.cache.NamedCacheApiProvider@6f7b9e34)) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1)
  while locating play.api.cache.CacheApi annotated with @play.cache.NamedCache(value=play)
  while locating play.api.cache.CacheApi
    for parameter 0 at play.cache.DefaultCacheApi.<init>(DefaultCacheApi.java:20)
  at play.cache.DefaultCacheApi.class(DefaultCacheApi.java:20)
  while locating play.cache.DefaultCacheApi
  while locating play.cache.CacheApi

1 error]

我正在为一些演员使用缓存(一个命名的,而不是默认的play)。我怎么能解决这个问题?

谢谢!

2 个答案:

答案 0 :(得分:0)

您是否禁用了EHCache?

application.conf: -

# disable default Play framework cache plugin
play.modules.disabled += "play.api.cache.EhCacheModule"

答案 1 :(得分:0)

我在较新的帖子EhCache instance with name 'play' already exists中找到了解决方案。这只是解决方法,但确实有效,关键部分是:

 lifecycle.addStopHook { () =>
    logger.info("CacheInstance stopped")
    Future.successful(CacheManager.getInstance().shutdown())
  }

设置完整代码的帖子。