Play 2.4 Global.java onStart called multiple times

171 views Asked by At

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?

1

There are 1 answers

0
Woodz On

After debugging through play.api.Play.scala#start, it appears that the Global plugin is being registered twice. Putting a breakpoint in play.api.Plugins.scala#loadPluginClassNames reveals that there are two resource files called play.plugins on 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.plugins file that only registers a single Global plugin - hence only calls Global.onStart once.