Documentation

You are viewing the documentation for the 2.5.8 release in the 2.5.x series of releases. The latest stable release series is 3.0.x.

§Global Settings

Note: The GlobalSettings class is deprecated in 2.5.x. Please see the Removing `GlobalSettings` page for how to migrate away from GlobalSettings.

§The Global object

Defining a Global class in your project allows you to handle global settings for your application:

import play.*;

public class Global extends GlobalSettings {

}

By default, this object is defined in the root package, but you can define it wherever you want and then configure it in your application.conf using application.global property.

§Intercepting application start-up and shutdown

You can override the onStart and onStop operation to be notified of the corresponding application lifecycle events:

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...");
    }

}

§Overriding onRequest

One important aspect of the GlobalSettings class is that it provides a way to intercept requests and execute business logic before a request is dispatched to an action.

For example:

public class Global extends GlobalSettings {

    public Action onRequest(Http.Request request, Method actionMethod) {
        System.out.println("before each request..." + request.toString());
        return super.onRequest(request, actionMethod);
    }

}

It’s also possible to intercept a specific action method. This can be achieved via Action composition.

Next: Testing your application