我刚刚将我的应用程序从 play framework 2.3.9 升级到了 2.4.6。一切正常,但 onstart(Application app) 方法被执行了两次。由于我在 onstart 方法中创建了一些调度程序,它们也被执行了两次。
全球.java
public class Global extends GlobalSettings {
public void onStart(Application app) {
Logger.info("Application has started");
JPA.withTransaction(() -> {
if (ConfigHelper.getGlobalValue("install").equalsIgnoreCase("xyz")) {
Logger.info("Starting pqr scheduler");
ActorRef myActor = Akka.system().actorOf(
Props.create(PQR.class));
FiniteDuration delay = FiniteDuration.create(0, TimeUnit.SECONDS);
FiniteDuration frequency = FiniteDuration.create(10, TimeUnit.MINUTES);
Akka.system()
.scheduler()
.schedule(delay, frequency, myActor, "start", Akka.system().dispatcher(), myActor);
}
});
}
public void onStop(Application app) {
Logger.info("Application shutdown...");
}
}
plugin.sbt 文件如下
logLevel := Level.Warn
resolvers += "Typesafe repository" at "https://repo.typesafe.com/typesafe/releases/"
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.6")
addSbtPlugin("de.johoop" % "jacoco4sbt" % "2.1.6")
addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "2.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-play-enhancer" % "1.1.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.1")
addSbtPlugin("net.ground5hark.sbt" % "sbt-css-compress" % "0.1.3")
addSbtPlugin("net.ground5hark.sbt" % "sbt-closure" % "0.1.3")
addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.1.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-gzip" % "1.0.0")
build.sbt 如下:
name := "project name"
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayJava)
scalaVersion := "2.11.7"
libraryDependencies ++= Seq(
javaJdbc, javaJpa, cache, javaWs,
"org.hibernate" % "hibernate-entitymanager" % "4.3.9.Final",
"mysql" % "mysql-connector-java" % "5.1.35",
"com.amazonaws" % "aws-java-sdk-ses" % "1.9.38",
"com.amazonaws" % "aws-java-sdk-s3" % "1.9.38",
"org.freemarker" % "freemarker" % "2.3.22"
)
resolvers += "Sonatype" at "url"
credentials += Credentials("Repository Manager", "***", "***", "****")
注意:我在项目中使用 jpa。任何帮助将不胜感激。