0
votes

I have a project in play framework that I would like to have preloaded with some data when the application is first built (after running 'activator run').

From what I understand that used to be achieved by creating a 'initial-data.yml' file in the /conf folder and then having a Bootstrap.java file such as the following:

import play.*;
import play.jobs.*;
import play.test.*;

import models.*;

@OnApplicationStart
public class Bootstrap extends Job {

    public void doJob() {
        // Check if the database is empty
        if(User.count() == 0) {
            Fixtures.load("initial-data.yml");
        }
    }

}

However, that no longer works.

How do I preload data into my project in play framework 2.3.3?

1

1 Answers

0
votes

You can use the Global object.

import play.*;

public class Global extends GlobalSettings {

    @Override
    public void onStart(Application app) {
        //data load logic goes here
    }

}

just don't forget to place this object in the root package.

Documentation --> https://www.playframework.com/documentation/2.3.x/JavaGlobal

Apidoc --> https://www.playframework.com/documentation/2.3.x/api/java/index.html