升级到Play 2.5.0之后:java.lang.RuntimeException:没有启动的应用程序

时间:2016-03-06 13:15:23

标签: scala playframework

我尝试将我的应用更新为Play 2.5.0。 OneAppPerTest的所有测试都不再运行了。该应用程序也不再运行。我可以使用sbt run启动应用,但我的第一个请求会显示相同的错误消息:

java.lang.RuntimeException: There is no started application.  

我确实混合了DI和特征,它在游戏2.4.6中正常运行。 我不知道现在在哪里搜索。有没有人有同样的问题?

Error injecting constructor, java.lang.RuntimeException: There is no started application
  at com.myproject.controllers.MyController.<init>(MyController.scala:30)
  at com.myproject.controllers.MyController.class(MyController.scala:30)
  while locating com.myproject.controllers.MyController
    for parameter 7 at router.Routes.<init>(Routes.scala:79)
  while locating router.Routes
  while locating play.api.inject.RoutesProvider
  while locating play.api.routing.Router
    for parameter 0 at play.api.http.JavaCompatibleHttpRequestHandler.<init>(HttpRequestHandler.scala:200)
  while locating play.api.http.JavaCompatibleHttpRequestHandler
  while locating play.api.http.HttpRequestHandler
    for parameter 4 at play.api.DefaultApplication.<init>(Application.scala:220)
  at play.api.DefaultApplication.class(Application.scala:220)
  while locating play.api.DefaultApplication
  while locating play.api.Application
Caused by: java.lang.RuntimeException: There is no started application
        at scala.sys.package$.error(package.scala:27)
        at play.api.Play$$anonfun$current$1.apply(Play.scala:86)
        at play.api.Play$$anonfun$current$1.apply(Play.scala:86)
        at scala.Option.getOrElse(Option.scala:121)
        at play.api.Play$.current(Play.scala:86)
        at com.myproject.model.dao.DAOSlick$class.dbConfig(DAOSlick.scala:11)
        at com.myproject.controllers.MyController.dbConfig$lzycompute(MyController.scala:30)
        at com.myproject.controllers.MyController.dbConfig(MyController.scala:30)
        at play.api.db.slick.HasDatabaseConfig$class.driver(DatabaseConfigProvider.scala:142)
        at com.myproject.controllers.MyController.driver$lzycompute(MyController.scala:30)
        at com.myproject.controllers.MyController.driver(MyController.scala:30)
        at com.myproject.controllers.MyController.driver(MyController.scala:30)
        at com.myproject.model.dao.JavaTimeMapper$class.$init$(JavaTimeMapper.scala:20)
        at com.myproject.controllers.MyController.<init>(MyController.scala:30)
        at com.myproject.controllers.MyController$$FastClassByGuice$$b68ea36a.newInstance(<generated>)
        at com.google.inject.internal.cglib.reflect.$FastConstructor.newInstance(FastConstructor.java:40)

这是我的DAOSlick Trait,它使用已弃用的Play.current

import play.api.Play
import play.api.db.slick.DatabaseConfigProvider
import slick.driver.JdbcProfile

trait DAOSlick {
  protected lazy val dbConfig = DatabaseConfigProvider.get[JdbcProfile]("default")(Play.current) // this is line 11, where it fails
  protected val driver: JdbcProfile
  import driver.api._
}

以下是&#34; MyController&#34;:

的负责人
@Singleton
class WebsocketController @Inject() (redis: RedisService, notificationService: NotificationService) extends SecuredController with SomeService {

注入的服务NotificationService和特征SomeService都在扩展DAOSlick Trait。

有人可以给我一个提示,如何将DAOSlick中的依赖关系更改为Play.current

1 个答案:

答案 0 :(得分:3)

看起来DatabaseConfig via Global Lookup已过期。我建议不要使用全局查找,而是完全切换到依赖注入:

import javax.inject.Inject
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import slick.driver.JdbcProfile

class SomeDao @Inject()(protected val dbConfigProvider: DatabaseConfigProvider) extends HasDatabaseConfigProvider[JdbcProfile] {
  import driver.api._

  // dao stuff...
}

不确定全局查询是否仍然是一个问题......可能不是Play.current的取消。如果我错了,请纠正我。