问题
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 ?
回答1:
As said : This is by design. If you want to see it in action from sbt, run sbt testProd instead of sbt run.
来源:https://stackoverflow.com/questions/46062618/playframework-2-6-x-execute-application-startup-code