playframework - Play java framework Initializing variables on application startup in -


i want initialise variables on application startup in play framework. i'm following document http://www.playframework.com/documentation/2.2.x/javaglobal doing same.. when run application command "play run" initialization not happen. doing wrong here?

import com.constants;  import controllers.application; import controllers.utils; import play.*;  public class global extends globalsettings {   public void onstart(application app) throws exception {     logger.info("application has started");     constants.data1= utils.getmerchanttobrmapping(utils.getmerchantname());     constants.data2 = utils.getbrtomerchantmapping(utils.getmerchantname());     logger.info("loaded merchant br map");   } } 

your application controller being used implementation app parameter in onstart(applciation app) method.

in other words not overridding onstart() callback method play call, instead defining own custom method.

it should rather this:

import play.application; import play.globalsettings; import play.logger;  import controllers.utils; import com.constants;  public class global extends globalsettings {      @override     public void onstart(application app) {         logger.info("application has started");         constants.data1 = utils.getmerchanttobrmapping(utils.getmerchantname());         constants.data2 = utils.getbrtomerchantmapping(utils.getmerchantname());         logger.info("loaded merchant br map");     } } 

note import of import play.application; , not controller. note onstart() not throw exception. if had added @override annotation have hinted @ problem, keep in mind future reference.

more on global here


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -