本文整理汇总了Java中org.cfg4j.source.context.filesprovider.ConfigFilesProvider类的典型用法代码示例。如果您正苦于以下问题:Java ConfigFilesProvider类的具体用法?Java ConfigFilesProvider怎么用?Java ConfigFilesProvider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConfigFilesProvider类属于org.cfg4j.source.context.filesprovider包,在下文中一共展示了ConfigFilesProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configurationProvider
import org.cfg4j.source.context.filesprovider.ConfigFilesProvider; //导入依赖的package包/类
@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();
}
示例2: configurationProvider
import org.cfg4j.source.context.filesprovider.ConfigFilesProvider; //导入依赖的package包/类
@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();
}
示例3: configurationProvider
import org.cfg4j.source.context.filesprovider.ConfigFilesProvider; //导入依赖的package包/类
@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();
}
示例4: getConfigurationThrowsOnMalformedConfigFile
import org.cfg4j.source.context.filesprovider.ConfigFilesProvider; //导入依赖的package包/类
@Test
public void getConfigurationThrowsOnMalformedConfigFile() throws Exception {
configFilesProvider = new ConfigFilesProvider() {
@Override
public Iterable<Path> getConfigFiles() {
return Collections.singletonList(
Paths.get("malformed.properties")
);
}
};
source = new FilesConfigurationSource(configFilesProvider);
expectedException.expect(IllegalStateException.class);
source.getConfiguration(environment);
}
示例5: getConfigurationThrowsOnMissingConfigFile
import org.cfg4j.source.context.filesprovider.ConfigFilesProvider; //导入依赖的package包/类
@Test
public void getConfigurationThrowsOnMissingConfigFile() throws Exception {
configFilesProvider = new ConfigFilesProvider() {
@Override
public Iterable<Path> getConfigFiles() {
return Collections.singletonList(
Paths.get("nonexistent.properties")
);
}
};
source = new ClasspathConfigurationSource(configFilesProvider);
expectedException.expect(IllegalStateException.class);
source.getConfiguration(new DefaultEnvironment());
}
示例6: getConfigurationThrowsOnMalformedConfigFile
import org.cfg4j.source.context.filesprovider.ConfigFilesProvider; //导入依赖的package包/类
@Test
public void getConfigurationThrowsOnMalformedConfigFile() throws Exception {
configFilesProvider = new ConfigFilesProvider() {
@Override
public Iterable<Path> getConfigFiles() {
return Collections.singletonList(
Paths.get("malformed.properties")
);
}
};
source = new ClasspathConfigurationSource(configFilesProvider);
expectedException.expect(IllegalStateException.class);
source.getConfiguration(new DefaultEnvironment());
}
示例7: getConfigurationSource
import org.cfg4j.source.context.filesprovider.ConfigFilesProvider; //导入依赖的package包/类
private ConfigurationSource getConfigurationSource(Path configFilePath) {
ConfigFilesProvider configFilesProvider = () ->
ImmutableList.of(configFilePath);
if (configFilePath.isAbsolute()) {
LOGGER.debug("loading config from: {}", configFilePath);
return new FilesConfigurationSource(configFilesProvider);
} else {
LOGGER.debug("loading config from classpath");
return new ClasspathConfigurationSource(configFilesProvider);
}
}
示例8: FilesConfigurationSource
import org.cfg4j.source.context.filesprovider.ConfigFilesProvider; //导入依赖的package包/类
/**
* Construct {@link ConfigurationSource} backed by files. Uses "application.properties" file
* located in the path specified by the {@link Environment} provided to {@link #getConfiguration(Environment)}
* calls (see corresponding javadoc for detail).
*/
public FilesConfigurationSource() {
this(new ConfigFilesProvider() {
@Override
public Iterable<Path> getConfigFiles() {
return Collections.singletonList(
Paths.get("application.properties")
);
}
});
}
示例9: ClasspathConfigurationSource
import org.cfg4j.source.context.filesprovider.ConfigFilesProvider; //导入依赖的package包/类
/**
* Construct {@link ConfigurationSource} backed by classpath files. Uses "application.properties" file
* located in the path specified by the {@link Environment} provided to {@link #getConfiguration(Environment)}
* calls (see corresponding javadoc for detail).
*/
public ClasspathConfigurationSource() {
this(new ConfigFilesProvider() {
@Override
public Iterable<Path> getConfigFiles() {
return Collections.singletonList(
Paths.get("application.properties")
);
}
});
}
示例10: getConfigurationReadsFromGivenFiles
import org.cfg4j.source.context.filesprovider.ConfigFilesProvider; //导入依赖的package包/类
@Test
public void getConfigurationReadsFromGivenFiles() throws Exception {
configFilesProvider = new ConfigFilesProvider() {
@Override
public Iterable<Path> getConfigFiles() {
return Arrays.asList(
Paths.get("application.properties"),
Paths.get("otherConfig.properties")
);
}
};
source = new FilesConfigurationSource(configFilesProvider);
assertThat(source.getConfiguration(environment)).containsOnlyKeys("some.setting", "otherConfig.setting");
}
示例11: getConfigurationReadsFromGivenFiles
import org.cfg4j.source.context.filesprovider.ConfigFilesProvider; //导入依赖的package包/类
@Test
public void getConfigurationReadsFromGivenFiles() throws Exception {
configFilesProvider = new ConfigFilesProvider() {
@Override
public Iterable<Path> getConfigFiles() {
return Arrays.asList(
Paths.get("application.properties"),
Paths.get("otherConfig.properties")
);
}
};
source = new ClasspathConfigurationSource(configFilesProvider);
assertThat(source.getConfiguration(new DefaultEnvironment())).containsOnlyKeys("some.setting", "otherConfig.setting");
}
示例12: getConfigurationProvider
import org.cfg4j.source.context.filesprovider.ConfigFilesProvider; //导入依赖的package包/类
private ConfigurationProvider getConfigurationProvider(final String path) {
ConfigurationSource source = new ClasspathConfigurationSource(new ConfigFilesProvider() {
@Override
public Iterable<Path> getConfigFiles() {
return Collections.singleton(Paths.get(path));
}
});
return new ConfigurationProviderBuilder()
.withConfigurationSource(source)
.build();
}
示例13: getConfigurationReadsFromGivenFiles
import org.cfg4j.source.context.filesprovider.ConfigFilesProvider; //导入依赖的package包/类
@Test
public void getConfigurationReadsFromGivenFiles() throws Exception {
ConfigFilesProvider configFilesProvider = new ConfigFilesProvider() {
@Override
public Iterable<Path> getConfigFiles() {
return Arrays.asList(Paths.get("application.properties"), Paths.get("otherConfig.properties"));
}
};
Environment environment = new DefaultEnvironment();
try (GitConfigurationSource gitConfigurationSource = getSourceForRemoteRepoWithFilesProvider(configFilesProvider)) {
assertThat(gitConfigurationSource.getConfiguration(environment)).containsKeys("some.setting", "otherConfig.setting");
}
}
示例14: getConfigurationThrowsOnMalformedConfigFile
import org.cfg4j.source.context.filesprovider.ConfigFilesProvider; //导入依赖的package包/类
@Test
public void getConfigurationThrowsOnMalformedConfigFile() throws Exception {
ConfigFilesProvider configFilesProvider = new ConfigFilesProvider() {
@Override
public Iterable<Path> getConfigFiles() {
return Collections.singletonList(Paths.get("malformed.properties"));
}
};
expectedException.expect(IllegalStateException.class);
getSourceForRemoteRepoWithFilesProvider(configFilesProvider).getConfiguration(new DefaultEnvironment());
}
示例15: getSourceForRemoteRepoWithFilesProvider
import org.cfg4j.source.context.filesprovider.ConfigFilesProvider; //导入依赖的package包/类
private GitConfigurationSource getSourceForRemoteRepoWithFilesProvider(ConfigFilesProvider configFilesProvider) {
GitConfigurationSource source = getSourceBuilderForRemoteRepoWithDefaults()
.withConfigFilesProvider(configFilesProvider)
.build();
source.init();
return source;
}