I want to use google guice to make properties available in all classes of my application. I defined a Module which loads and binds the properties file Test.properties.<
The library Guice configuration can inject for you values from Properties or JSON files to your services.
You can inject from the file application.properties to your service as :
@BindConfig(value = "application", syntax = PROPERTIES)
public class Service {
@InjectConfig
private int port;
@InjectConfig
private String url;
@InjectConfig
private Optional timeout;
}
You must simply install the modules ConfigurationModule
public class GuiceModule extends AbstractModule {
@Override
protected void configure() {
install(ConfigurationModule.create());
requestInjection(Service.class);
}
}