0

I am very new to play framework. I am trying to do something when my application will start and also do something when application will stop. I started searching for the entry and finish points and found out that in the 2.0 documentation there is ScalaGlobal where i can override the onStart, onStop and onError methods and do something inside it. For example:

object Global extends GlobalSettings {

  override def onStart(app: Application) {
    Logger.info("Application has started")
  }  

  override def onStop(app: Application) {
    Logger.info("Application shutdown...")
  }  

}

This code works fine for me in scala. But it is deprecated. But i could't find anything like that in 2.5.x documentation. Is there any methods to access the Start and Stop points of an application in play framework??

  1. How can i access the lifecycle methods in play framework??

EDIT: Is there any callbacks in play framework where any request will go through that method and then to others when certain methods are called like global ajax event handlers ??

Setu Kumar Basak
  • 11,460
  • 9
  • 53
  • 85

2 Answers2

1

To replace onStart method you need to define EagerBindings in new module: https://www.playframework.com/documentation/2.5.x/ScalaDependencyInjection#Eager-bindings

To replace onStop method you need to register some code on stop hook: https://www.playframework.com/documentation/2.5.x/ScalaDependencyInjection#Stopping/cleaning-up

To replace onError you need to define own error handler and add proper configuration in application.conf: https://www.playframework.com/documentation/2.5.x/ScalaErrorHandling

More information about migration to Play 2.5.x: https://www.playframework.com/documentation/2.5.x/GlobalSettings

mgosk
  • 1,874
  • 14
  • 23
  • I saw the links you have given but i don't know why it looked very complex to me.. The previous Global Settings were easy enough because it was like the activity lifecycle of android as i was an android developer. Is there any other simple example where the eager bindings, error handing or stoppings are nicely illustrated like how it works in detail ?? – Setu Kumar Basak May 31 '16 at 10:24
  • Sorry, but I don't know exact examples. All presented mechanisms are based on `dependency injection` and it should be a start for further research https://www.google.pl/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=play%20dependency%20injection – mgosk May 31 '16 at 10:40
-1

You need to follow the source code of Play : Comment in Play code

You can do something in Global.java when the application starts or shuts down like this : Global.java

Peter Neyens
  • 9,770
  • 27
  • 33
zhicheng
  • 36
  • 5