简体   繁体   English

将playframework升级到2.4.6后,Global.java的onstart方法执行了两次

[英]onstart method of Global.java getting executed twice after upgrading playframework to 2.4.6

I have just upgraded my application from play framework 2.3.9 to 2.4.6. 我刚刚将我的应用程序从播放框架2.3.9升级到了2.4.6。 Everything is working fine, but onstart(Application app) method getting executed twice. 一切工作正常,但是onstart(Application app)方法执行了两次。 As i have created some scheduler in the onstart method, they are also getting executed twice. 当我在onstart方法中创建了一些调度程序时,它们也被执行两次。

Global.java Global.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 file is as below 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 is as below: 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", "***", "***", "****")

Note: I am using jpa in the project. 注意:我在项目中使用jpa。 Any help would be highly appreciated. 任何帮助将不胜感激。

I had the same issue on production, not on dev mode. 我在生产上遇到了同样的问题,而不是在开发模式下。

I was running production on heroku on multiple dynos and the Global.java (and my background jobs triggered from Global.java) were executed as many times as my number of dynos. 我在heroku上的多个dyno上运行生产,并且Global.java(以及从Global.java触发的后台作业)执行的次数与我的dyno次数相同。

Here is an answer on how to execute it only once: Play 2 Heroku startup with multiple dynos 这是一个仅执行一次的答案: 播放2次带有多个测功器的Heroku启动

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 应用程序启动后,Playframework退出日志记录,但可用于Global.onStart() - Playframework quit logging after application starts, but works for Global.onStart() java Playframework对于onStart的GlobalSettings弃用 - java Playframework GlobalSettings deprecation for onStart Play框架Global.java中的多个过滤器 - Play Framework Multiple filters in Global.java 执行其他控制器方法的JPA.withTransaction方法错误:Global.java:39:错误:此处不允许使用“无效”类型 - JPA.withTransaction executing other controllers method error: Global.java:39: error: 'void' type not allowed here Spark Java Map 函数被执行两次 - Spark Java Map function is getting executed twice Play Framework 2.X:使用onReqest处理并在Global.java中重定向 - Play Framework 2.X : Dealing w/ onReqest and redirect in Global.java 在建议执行两次之前...相同的连接点列出两次相同的方法,因此它被调用两次 - Before advice getting executed twice…same join point listed twice for same method so it gets called twice 因此,当我将代码部署到CloudBees global.java时将无法运行(Play Framework 2.1) - So when I deploy my code to CloudBees global.java won't run (Play Framework 2.1) Java for循环执行两次 - Java for loop executed twice Libgdx Android:onCreate()之后未调用方法onStart() - Libgdx Android: method onStart() not called after onCreate()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM