Sorry if this question turns to be silly, but I simply cannot find my mistake and I checked already plenty of posts here in SO and other sites. I have setup a Play 2.3.7 project using Java. I have created a Global.java file in the common package under the app directory. In that file I override onStart (and other hooks) but I don't get them to work. They simply do not execute at all. Here's 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 the application.conf, here's the relevant part, which is commented by default:
# Define the common.Global object class for this application.
# Default to common.Global in the root package.
# application.global=common.Global
What can be the problem? Thanks.
It looks like you forgot to uncomment the application.global setting.
The following code worked just 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
The Global
object must reside in the default package, so you need to remove package common
.
As stated in the first paragraph of the documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With