Dropwizard: reading configuration from non-file source

What is the correct way to read the configuration in dropwizard from something like a database or calling a REST? I have a use case when I cannot have a yml file with some values ​​and should get settings / config during startup from a pre-configured URL using REST calls.

Is it possible to simply call these REST calls in the get methods of a class ApplicationConfiguration?

+4
source share
2 answers

As in my answer here , you implement the interface the ConfigurationSourceProviderway you want to implement, and configure the dropwizard application to use it in its Application class:

@Override
public void initialize(Bootstrap<MyConfiguration> bootstrap){
  bootstrap.setConfigurationSourceProvider(new MyDatabaseConfigurationSourceProvider());
}

InputStream YAML Configuration.

bootstrap.setConfigurationFactoryFactory(new MyDatabaseConfigurationFactoryFactory<>());

FactoryFactory:), Factory, InputStream Configuration.

public T build(ConfigurationSourceProvider provider, String path {
  Decode.onWhateverFormatYouWish(provider.open(path));
}
+5

, UrlConfigurationSourceProvider, dropwizard, URL-.

- :

@Override
public void initialize(Bootstrap<MyRestApplicationConfiguration> bootstrap) {
    bootstrap.setConfigurationSourceProvider(new UrlConfigurationSourceProvider());
}
+3

Source: https://habr.com/ru/post/1627963/


All Articles