@Bean public ConfigurationProvider configurationProvider() { // Specify which files to load. Configuration from both files will be merged. ConfigFilesProvider configFilesProvider = () -> Arrays.asList(Paths.get("application.yaml"), Paths.get("otherConfig.properties")); // Use local files as configuration store ConfigurationSource source = new FilesConfigurationSource(configFilesProvider); // Use relative paths Environment environment = new ImmutableEnvironment(filesPath); // Reload configuration every 5 seconds ReloadStrategy reloadStrategy = new PeriodicalReloadStrategy(5, TimeUnit.SECONDS); // Create provider return new ConfigurationProviderBuilder() .withConfigurationSource(source) .withReloadStrategy(reloadStrategy) .withEnvironment(environment) .build(); } }
@Test void suppressesException() { doThrow(new IllegalStateException()).when(reloadable).reload(); PeriodicalReloadStrategy strategy = new PeriodicalReloadStrategy(60, TimeUnit.SECONDS); strategy.register(reloadable); verify(reloadable, times(1)).reload(); } }
@Bean public ConfigurationProvider configurationProvider() { // Use Consul service as configuration store ConfigurationSource source = new ConsulConfigurationSourceBuilder().build(); // Reload configuration every 5 seconds ReloadStrategy reloadStrategy = new PeriodicalReloadStrategy(5, TimeUnit.SECONDS); // Create provider return new ConfigurationProviderBuilder() .withConfigurationSource(source) .withReloadStrategy(reloadStrategy) .build(); } }
@Bean public ConfigurationProvider configurationProvider() { // Specify which files to load. Configuration from both files will be merged. ConfigFilesProvider configFilesProvider = () -> Collections.singletonList(Paths.get("application.yaml")); // Use local files as configuration store ConfigurationSource source = new FilesConfigurationSource(configFilesProvider); // Use relative paths Environment environment = new ImmutableEnvironment(filesPath); // Reload configuration every 500 milliseconds ReloadStrategy reloadStrategy = new PeriodicalReloadStrategy(500, TimeUnit.MILLISECONDS); // Create provider return new ConfigurationProviderBuilder() .withConfigurationSource(source) .withReloadStrategy(reloadStrategy) .withEnvironment(environment) .withMetrics(metricRegistry, "firstProvider.") .build(); } }
@Bean public ConfigurationProvider configurationProvider() { // Specify which files to load. Configuration from both files will be merged. ConfigFilesProvider configFilesProvider = () -> Arrays.asList(Paths.get("application.properties"), Paths.get("otherConfig.properties")); // Use Git repository as configuration store ConfigurationSource source = new GitConfigurationSourceBuilder() .withRepositoryURI(configRepoPath) .withConfigFilesProvider(configFilesProvider) .build(); // Select branch to use (use new DefaultEnvironment()) for master Environment environment = new ImmutableEnvironment(branch); // Reload configuration every 5 seconds ReloadStrategy reloadStrategy = new PeriodicalReloadStrategy(5, TimeUnit.SECONDS); // Create provider return new ConfigurationProviderBuilder() .withConfigurationSource(source) .withEnvironment(environment) .withReloadStrategy(reloadStrategy) .build(); } }
@Test void reloadsImmediatelyAfterRegistered() { PeriodicalReloadStrategy strategy = new PeriodicalReloadStrategy(60, TimeUnit.SECONDS); strategy.register(reloadable); strategy.deregister(reloadable); verify(reloadable, times(1)).reload(); }
@Bean public ConfigurationProvider configurationProvider() { // Use Git repository as configuration store ConfigurationSource source = new GitConfigurationSourceBuilder() .withRepositoryURI(configRepoPath) .build(); // Select branch to use (use new DefaultEnvironment()) for master Environment environment = new ImmutableEnvironment(branch); // Reload configuration every 5 seconds ReloadStrategy reloadStrategy = new PeriodicalReloadStrategy(5, TimeUnit.SECONDS); // Create provider return new ConfigurationProviderBuilder() .withConfigurationSource(source) .withEnvironment(environment) .withReloadStrategy(reloadStrategy) .build(); } }
@Bean public ConfigurationProvider configurationProvider() { // Use Git repository as configuration store ConfigurationSource source = new GitConfigurationSourceBuilder() .withRepositoryURI(configRepoPath) .build(); // Select branch to use (use new DefaultEnvironment()) for master Environment environment = new ImmutableEnvironment(branch); // Reload configuration every 5 seconds ReloadStrategy reloadStrategy = new PeriodicalReloadStrategy(5, TimeUnit.SECONDS); // Create provider return new ConfigurationProviderBuilder() .withConfigurationSource(source) .withEnvironment(environment) .withReloadStrategy(reloadStrategy) .build(); } }