为什么游戏框架无法运行我的游戏? 编辑:

问题描述

我最近从scala-play-react-seed开始了一个新项目。

我对Play有一点经验,还有其他一些使用play-slick和slick-evolutions的项目-一切正常,并且在启动时就可以识别和应用这些变化。

在新项目中,这没有发生。我与数据库的连接一切正常,所以这不是问题。

据我所知,我没有任何关于进化的错误或警告。

我尝试在application.conf中显式打开它们。

这是我的build.sbt

// core
libraryDependencies ++= Seq(
  evolutions,ehcache,ws,specs2 % Test,guice)

libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "4.0.2" % Test

// database
libraryDependencies += "com.typesafe.play" %% "play-slick" % "4.0.2"
libraryDependencies += "com.typesafe.play" %% "play-slick-evolutions" % "4.0.2"
libraryDependencies += "org.postgresql" % "postgresql" % "9.4-1201-jdbc41"

我怀疑React UI中的钩子正在阻止后端以某种方式拾取那些文件,但不知道从哪里开始寻找。任何帮助都将不胜感激。

编辑:

我很确定我的application.conf设置正确,但是这里是:

slick.dbs.default.profile = "slick.jdbc.PostgresProfile$"
slick.dbs.default.db.driver = "org.postgresql.Driver"
slick.dbs.default.db.url = "jdbc:postgresql://localhost:5432/standups?user=postgres&password=password"

正如我之前所说,我非常确定此设置正确,因为我可以与数据库对话。只是没有被接受而已。

这是我的1.sql,位于conf/evolutions/default

-- !Ups

create table person
(
    id       serial       not null primary key,name     varchar(255) not null,age      smallint     not null
);

-- !Downs

drop table if exists person cascade;

解决方法

我不清楚为什么您的进化无法正常运行。

我已尝试在此提交中模拟您的设置:https://github.com/d6y/scala-play-react-seed/commit/408853bda6f26a7a4fdc49487c2bb00d243ac0dc

...我必须修改FrontendRunHook才能真正启动前端和服务器(通过https://github.com/yohangz/scala-play-react-seed/pull/30)。

除此之外,sbt run启动了应用程序并应用了演变过程(通过查看数据库进行了验证)。

我添加了play.evolutions.db.default.autoApply = true,但如果没有这样做,您会被告知数据库需要迁移。

我还与此同时使用了JDK 8,以避免出现与Guice(WARNING: An illegal reflective access operation has occurred)有关的警告。但是,您没有提到看到的内容,因此可能也没有关系。

,

您需要启用播放进化配置参数

https://www.playframework.com/documentation/2.8.x/Evolutions

play.evolutions.enabled=true


For example,to enable autoApply for all evolutions,you might set play.evolutions.autoApply=true in application.conf or in a system property. To disable autocommit for a datasource named default,you set play.evolutions.db.default.autocommit=false
,

在项目启动时,您还需要在某个时候致电{ "store": { "book": [ { "category": "reference","author": "Nigel Rees","title": "Sayings of the Century","price": 8.95 },{ "category": "fiction","author": "Evelyn Waugh","title": "Sword of Honour","price": 12.99 "available":false },"author": "Herman Melville","title": "Moby Dick","isbn": "0-553-21311-3","price": 8.99 },"author": "J. R. R. Tolkien","title": "The Lord of the Rings","isbn": "0-395-19395-8","price": 22.99 } ],"bicycle": { "color": "red","price": 19.95 } },"expensive": 10 }

通常在applicationEvolutions的实例中完成。

这意味着:

  1. 为您的应用程序“组件”添加一个类,其中包括扩展ApplicationLoader和访问DBComponents with EvolutionsComponents
  2. 编写一个扩展了applicationEvolutions的类,该类通过ApplicationLoader的{​​{1}}方法重新调整您的组件。
  3. 将完全限定的类作为load添加到您的ApplicationLoader

您可以在https://www.playframework.com/documentation/2.8.x/ScalaCompileTimeDependencyInjection#Application-entry-point

上查看application.conf及其组件的轮廓。

在数据库代码中混合以调用play.application.loader=your.package.name.here.MyAppLoader的细节位于:https://www.playframework.com/documentation/2.8.x/Evolutions#Enable-evolutions