Using Play framework v2.4.3, I have the following Global.java in the root namespace as per the documentation at https://www.playframework.com/documentation/2.4.x/JavaGlobal#Intercepting-application-start-up-and-shutdown:
import play.*;
public class Global extends GlobalSettings {
public void onStart(Application app) {
Logger.info("Application has started");
}
public void onStop(Application app) {
Logger.info("Application shutdown...");
}
}
However, when starting up the application in either production or test, the logs show
Application has started
Application has started
Why is this callback being called twice?
After debugging through
play.api.Play.scala#start, it appears that theGlobalplugin is being registered twice. Putting a breakpoint inplay.api.Plugins.scala#loadPluginClassNamesreveals that there are two resource files calledplay.pluginson the classpath - due to a dependency mismatch that is causing both Play 2.4.3 and 2.4.6 from being pulled in.By correcting the dependency versions or filtering out the incorrect Play dependency JAR so that there is only a single Play JAR on the classpath, there is only a single
play.pluginsfile that only registers a singleGlobalplugin - hence only callsGlobal.onStartonce.