René,
I'm sorry for the confusion, I replied in haste as I didn't have much time yesterday.
Here is how you can set things up:
1) Create a class called modules.MyModule with the following contents:
package modules;
import com.google.inject.AbstractModule;
public class MyModule extends AbstractModule {
@Override
public void configure() {
bind(AppStartup.class).asEagerSingleton();
}
}
2) Create a class called modules.AppStartup with the following contents (this assumes you're using Ebean for database access):
package modules;
import play.Configuration;
import play.Environment;
import play.Logger;
import play.inject.ApplicationLifecycle;
import play.db.ebean.EbeanConfig;
import play.db.ebean.EbeanDynamicEvolutions;
class AppStartup {
private final Environment environment;
private final Configuration configuration;
@Inject
public AppStartup(ApplicationLifecycle lifecycle, Environment environment, Configuration configuration, EbeanDynamicEvolutions dynamicEvolutions, EbeanConfig ebeanConfig) {
// adding EbeanDynamicEvolutions and EbeanConfig will allow Ebean to start up prior to this constructor running
this.environment = environment;
this.configuration = configuration;
// onStart
onStart();
lifecycle.addStopHook( () -> {
// onStop
return CompletableFuture.completedFuture(null);
}
}
public void onStart() {
Logger.debug("Configuration item: " + this.configuration.getString("foo.bar.baz"));
// Commented the following out since it's just to show using Ebean and won't actually work unless you have a BeanClass class, a database, etc:
//
// BeanClass bc = Ebean.find(BeanClass.class).where().eq("id", 1).findUnique();
3) In your conf/ folder, create a file called reference.conf with the following contents: