小编Bha*_*vya的帖子

Play 2.4测试出错:CacheManager已关闭.它不能再使用了

我们的应用程序基于Play 2.4与Scala 2.11和Akka构建.使用的数据库是MySQL.

缓存在我们的应用程序中大量使用.我们使用Play的默认EhCache进行缓存.

我们的示例代码段:

import play.api.Play.current
import play.api.cache.Cache

case class Sample(var id: Option[String],
                 //.. other fields
)

class SampleTable(tag: Tag)
  extends Table[Sample](tag, "SAMPLE") {
  def id = column[Option[String]]("id", O.PrimaryKey)
  // .. other field defs
}

object SampleDAO extends TableQuery(new SampleTable(_)) with SQLWrapper {
  def get(id: String) : Future[Sample] = {
    val cacheKey = // our code to generate a unique cache key
    Cache.getOrElse[Future[[Sample]](cacheKey) {
      db.run(this.filter(_.id === id).result.headOption)
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我们使用Play的内置Specs2进行测试. …

junit caching ehcache scala-2.11 playframework-2.4

10
推荐指数
1
解决办法
2688
查看次数

使用Play2.4和scala的Google Guice的循环依赖性错误

我的应用程序使用Play 2.4和Scala 2.11.我开始转换现有代码以使用Play 2.4附带的Google Guice.

当我在进行第一组更改后运行代码时,我发现代码中的某些DAO失败并出现循环依赖性错误.

例如,我有两个DAO

class BookDAO @Inject()
(protected val personDAO : PersonDAO,
 @NamedDatabase("mysql")protected val dbConfigProvider: DatabaseConfigProvider) extends HasDatabaseConfigProvider[JdbcProfile] {
...
...
val personId = //some id
personDAO.get(personId)
}

class PersonDAO @Inject()
(protected val bookDAO : BookDAO,
 @NamedDatabase("mysql")protected val dbConfigProvider: DatabaseConfigProvider) extends HasDatabaseConfigProvider[JdbcProfile] {
...
...
val bookName= //some id
personDAO.getByName(bookName)
}
Run Code Online (Sandbox Code Playgroud)

尝试访问BookDAO或PersonDAO时出现以下错误

Tried proxying schema.BookDAO to support a circular dependency, but it is not an interface.
  at schema.BookDAO.class(Books.scala:52)
  while locating schema.BookDAO
Run Code Online (Sandbox Code Playgroud)

有人可以帮我解决这个错误. …

scala guice playframework-2.4

5
推荐指数
1
解决办法
1299
查看次数

标签 统计

playframework-2.4 ×2

caching ×1

ehcache ×1

guice ×1

junit ×1

scala ×1

scala-2.11 ×1