playframeworkplayframework-2.0playframework-2.2playframework-2.3

PlayFramework 2.6.x - Execute Application Startup Code


This question is with regard to play! java 2.6.x

I am attempting to bootstrap some initialization code which needs to be executed during application startup

As per documentation, I have a class called Module in root package

  public class Module extends AbstractModule {

  private final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger("application");

  @Override
  public void configure() {
    logger.info("Loading Modules");
    bind(ConsumerBootstrap.class).asEagerSingleton();
  }

}

However it is not behaving as expected. The binding only occurs when I trigger a request on a specific route, rather than eager binding on application startup.

I am running the application using sbt run

Am I missing anything ?


Solution

  • As said : This is by design. If you want to see it in action from sbt, run sbt testProd instead of sbt run.