Global onStart on Play Framework 2.3.7 not working?

Sorry if this question becomes stupid, but I just can’t find my mistake, and I already checked a lot of posts here in SO and other sites. I created a Play 2.3.7 project using Java. I created the Global.java file in a common package in the application directory. In this file, I override onStart (and other hooks), but I do not make them work. They simply are not executed at all. Here is the Global.java file:

package common; import play.Application; import play.GlobalSettings; import play.Logger; public class Global extends GlobalSettings { @Override public void beforeStart(Application application) { Logger.error("good bye cruel world"); super.beforeStart(application); throw new RuntimeException("WTF"); } @Override public void onStart(Application application) { Logger.error("good bye cruel world"); super.onStart(application); throw new RuntimeException("WTF"); } @Override public void onStop(Application application) { Logger.error("good bye cruel world"); super.onStop(application); throw new RuntimeException("WTF"); } } 

And inside application.conf, here is the corresponding part, which is commented out by default:

 # Define the common.Global object class for this application. # Default to common.Global in the root package. # application.global=common.Global 

What could be the problem? Thanks.

+8
java scala playframework sbt
source share
2 answers

The Global object must be in the default package, so you need to remove package common .

As indicated in the first paragraph of the documentation .

+6
source share

It looks like you forgot to uncomment the application.global setting.

The following code worked fine for me.

Global.java file:

 package common; import play.Application; import play.GlobalSettings; import play.Logger; public class Global extends GlobalSettings { @Override public void beforeStart(Application application) { Logger.error("good bye cruel world"); super.beforeStart(application); } @Override public void onStart(Application application) { Logger.error("good bye cruel world"); super.onStart(application); } @Override public void onStop(Application application) { Logger.error("good bye cruel world"); super.onStop(application); } } 

application.conf file:

 # Define the Global object class for this application. # Default to Global in the root package. application.global=common.Global 
+8
source share

All Articles