本文整理汇总了Java中io.bootique.config.ConfigurationFactory类的典型用法代码示例。如果您正苦于以下问题:Java ConfigurationFactory类的具体用法?Java ConfigurationFactory怎么用?Java ConfigurationFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConfigurationFactory类属于io.bootique.config包,在下文中一共展示了ConfigurationFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testConfigEnvExcludes_System
import io.bootique.config.ConfigurationFactory; //导入依赖的package包/类
@Test
public void testConfigEnvExcludes_System() {
System.setProperty("bq.a", "bq_a");
System.setProperty("bq.c.m.k", "bq_c_m_k");
System.setProperty("bq.c.m.l", "bq_c_m_l");
BQRuntime runtime = testFactory.app("--config=src/test/resources/configEnvironment.yml").createRuntime();
Bean1 b1 = runtime.getInstance(ConfigurationFactory.class).config(Bean1.class, "");
assertEquals("e", b1.a);
assertEquals("q", b1.c.m.k);
assertEquals("n", b1.c.m.l);
System.clearProperty("bq.a");
System.clearProperty("bq.c.m.k");
System.clearProperty("bq.c.m.l");
}
示例2: configure
import io.bootique.config.ConfigurationFactory; //导入依赖的package包/类
@Override
public void configure(Binder binder) {
BQCoreModule.extend(binder)
.initAllExtensions()
.addOption(createConfigOption())
.addCommand(HelpConfigCommand.class);
// bind instances
binder.bind(BootLogger.class).toInstance(Objects.requireNonNull(bootLogger));
binder.bind(ShutdownManager.class).toInstance(Objects.requireNonNull(shutdownManager));
binder.bind(String[].class).annotatedWith(Args.class).toInstance(Objects.requireNonNull(args));
// deprecated, kept for those users who may have injected this in their own code
binder.bind(Duration.class).annotatedWith(ShutdownTimeout.class)
.toInstance(Objects.requireNonNull(Duration.ofMillis(10000L)));
// too much code to create config factory.. extracting it in a provider
// class...
binder.bind(ConfigurationFactory.class).toProvider(JsonNodeConfigurationFactoryProvider.class).in(Singleton.class);
}
示例3: get
import io.bootique.config.ConfigurationFactory; //导入依赖的package包/类
@Override
public ConfigurationFactory get() {
Map<String, String> vars = environment.frameworkVariables();
Map<String, String> properties = environment.frameworkProperties();
JsonNode rootNode = loadConfiguration(properties, vars);
ObjectMapper jsonToObjectMapper = jacksonService.newObjectMapper();
if (!vars.isEmpty()) {
// switching to slower CI strategy for mapping properties...
jsonToObjectMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
}
return new JsonNodeConfigurationFactory(rootNode, jsonToObjectMapper);
}
示例4: testDIOnOptionConfig
import io.bootique.config.ConfigurationFactory; //导入依赖的package包/类
@Test
public void testDIOnOptionConfig() {
Function<String, String> configReader =
arg -> {
BQRuntime runtime = runtimeFactory.app(arg)
.module(b -> BQCoreModule.extend(b)
.addConfigOnOption("opt", "classpath:io/bootique/diconfig1.yml")
.addConfigOnOption("opt", "classpath:io/bootique/diconfig2.yml")
.addOption(OptionMetadata.builder("opt").build()))
.createRuntime();
Map<String, Integer> config =
runtime.getInstance(ConfigurationFactory.class)
.config(new TypeRef<Map<String, Integer>>() {
}, "");
return config.toString();
};
assertEquals("{}", configReader.apply(""));
assertEquals("{a=1, b=2, c=3}", configReader.apply("--opt"));
}
示例5: testDIOnOptionConfig_OverrideWithOption
import io.bootique.config.ConfigurationFactory; //导入依赖的package包/类
@Test
public void testDIOnOptionConfig_OverrideWithOption() {
Function<String, String> configReader =
arg -> {
BQRuntime runtime = runtimeFactory.app(arg)
.module(b -> BQCoreModule.extend(b)
.addConfigOnOption("opt", "classpath:io/bootique/diconfig1.yml")
.addConfigOnOption("opt", "classpath:io/bootique/diconfig2.yml")
.addOption("a", "opt"))
.createRuntime();
return runtime.getInstance(ConfigurationFactory.class)
.config(new TypeRef<Map<String, Integer>>() {
}, "").toString();
};
assertEquals("{}", configReader.apply(""));
assertEquals("{a=8, b=2, c=3}", configReader.apply("--opt=8"));
}
示例6: testConfigEnvOverrides_Alias
import io.bootique.config.ConfigurationFactory; //导入依赖的package包/类
@Test
public void testConfigEnvOverrides_Alias() {
BQRuntime runtime = runtimeFactory.app("--config=src/test/resources/io/bootique/test3.yml")
.declareVar("a", "V1")
.declareVar("c.m.f", "V2")
.declareVar("c.m.k", "V3")
.var("V1", "K")
.var("V2", "K1")
.var("V3", "4")
.createRuntime();
Bean1 b1 = runtime.getInstance(ConfigurationFactory.class).config(Bean1.class, "");
assertEquals("K", b1.a);
assertEquals(4, b1.c.m.k);
assertEquals("n", b1.c.m.l);
assertEquals("K1", b1.c.m.f);
}
示例7: testConfigOverrideOrder_PropsVarsOptionsFileOptions
import io.bootique.config.ConfigurationFactory; //导入依赖的package包/类
@Test
public void testConfigOverrideOrder_PropsVarsOptionsFileOptions() {
System.setProperty("bq.c.m.f", "prop_c_m_f");
try {
BQRuntime runtime = runtimeFactory.app("--config=classpath:io/bootique/config/test4.yml", "--file-opt-1", "--opt-1=Option")
.module(binder -> BQCoreModule.extend(binder)
.addOption("c.m.f", "opt-1")
.addConfigResourceOption("classpath:io/bootique/config/configTest4Opt1.yml", "file-opt-1")
.setVar("BQ_C_M_F", "var_c_m_f"))
.createRuntime();
Bean1 bean1 = runtime.getInstance(ConfigurationFactory.class).config(Bean1.class, "");
Assert.assertEquals("f", bean1.c.m.f);
}
finally {
System.clearProperty("bq.c.m.f");
}
}
示例8: factory
import io.bootique.config.ConfigurationFactory; //导入依赖的package包/类
private static ConfigurationFactory factory(Map<String, String> propertyOverrides, Map<String, String> varOverrides,
String... yaml) {
ConfigurationSource mockSource = mock(ConfigurationSource.class);
when(mockSource.get()).thenReturn(asList(yaml).stream().map(s -> {
// need to store YAML on disk to have a URL for it
try {
Path dir = Paths.get("target", "junit", "tmp");
Files.createDirectories(dir);
Path tmp = Files.createTempFile(dir, "BQConfigurationFactoryProviderTest", ".yml");
Files.write(tmp, s.getBytes());
return tmp.toUri().toURL();
} catch (IOException e) {
throw new RuntimeException(e);
}
}));
Environment mockEnvironment = mock(Environment.class);
when(mockEnvironment.frameworkProperties()).thenReturn(propertyOverrides);
when(mockEnvironment.frameworkVariables()).thenReturn(varOverrides);
return factory(mockSource, mockEnvironment);
}
示例9: createDataSource
import io.bootique.config.ConfigurationFactory; //导入依赖的package包/类
@Singleton
@Provides
public DataSourceFactory createDataSource(
ConfigurationFactory configFactory,
BootLogger bootLogger,
ShutdownManager shutdownManager,
Set<DataSourceListener> listeners,
Injector injector) {
Map<String, ManagedDataSourceFactory> configs = configFactory
.config(new TypeRef<Map<String, ManagedDataSourceFactory>>() {
}, configPrefix);
LazyDataSourceFactory factory = new LazyDataSourceFactoryFactory(configs).create(injector, listeners);
shutdownManager.addShutdownHook(() -> {
bootLogger.trace(() -> "shutting down LazyDataSourceFactory...");
factory.shutdown();
});
return factory;
}
示例10: testInitFromConfig
import io.bootique.config.ConfigurationFactory; //导入依赖的package包/类
@Test
public void testInitFromConfig() {
ConfigurationFactory configFactory = LOGGER_STACK
.newBQRuntime("classpath:io/bootique/logback/test-multi-appender.yml")
.getInstance(ConfigurationFactory.class);
LogbackContextFactory rootFactory = configFactory.config(LogbackContextFactory.class, "log");
assertEquals(LogbackLevel.debug, rootFactory.getLevel());
assertNotNull(rootFactory.getAppenders());
assertEquals(2, rootFactory.getAppenders().size());
AppenderFactory[] appenders = rootFactory.getAppenders().toArray(new AppenderFactory[2]);
assertTrue(appenders[0] instanceof ConsoleAppenderFactory);
ConsoleAppenderFactory a1 = (ConsoleAppenderFactory) appenders[0];
assertEquals(ConsoleTarget.stderr, a1.getTarget());
assertEquals("%c{20}: %m%n", a1.getLogFormat());
assertTrue(appenders[1] instanceof FileAppenderFactory);
FileAppenderFactory a2 = (FileAppenderFactory) appenders[1];
assertEquals("%c{10}: %m%n", a2.getLogFormat());
assertEquals("target/logs/rotate/logfile123.log", a2.getFile());
}
示例11: provideHeartbeat
import io.bootique.config.ConfigurationFactory; //导入依赖的package包/类
@Provides
@Singleton
Heartbeat provideHeartbeat(
ConfigurationFactory configurationFactory,
HealthCheckRegistry registry,
Set<HeartbeatListener> listeners,
ShutdownManager shutdownManager) {
Heartbeat hb = configurationFactory
.config(HeartbeatFactory.class, "heartbeat")
.createHeartbeat(registry, listeners);
shutdownManager.addShutdownHook(() -> hb.stop());
return hb;
}
示例12: provideJooqFactory
import io.bootique.config.ConfigurationFactory; //导入依赖的package包/类
@Provides
@Singleton
JooqFactory provideJooqFactory(ConfigurationFactory configurationFactory, DataSourceFactory dataSourceFactory) {
return configurationFactory
.config(DefaultJooqFactoryFactory.class, configPrefix)
.createFactory(dataSourceFactory);
}
示例13: provideRealms
import io.bootique.config.ConfigurationFactory; //导入依赖的package包/类
@Provides
@Singleton
Realms provideRealms(Injector injector, ConfigurationFactory configurationFactory, Set<Realm> diRealms) {
return configurationFactory
.config(RealmsFactory.class, configPrefix)
.createRealms(injector, diRealms);
}
示例14: provideMappedShiroFilter
import io.bootique.config.ConfigurationFactory; //导入依赖的package包/类
@Singleton
@Provides
MappedFilter<ShiroFilter> provideMappedShiroFilter(ConfigurationFactory configFactory,
Injector injector,
WebSecurityManager securityManager,
@ShiroFilterBinding Map<String, Filter> chainFilters) {
return configFactory
.config(MappedShiroFilterFactory.class, configPrefix)
.createShiroFilter(injector, securityManager, chainFilters);
}
示例15: createClientFactory
import io.bootique.config.ConfigurationFactory; //导入依赖的package包/类
@Provides
@Singleton
HttpClientFactory createClientFactory(ConfigurationFactory configurationFactory, Injector injector,
@JerseyClientFeatures Set<Feature> features) {
return configurationFactory.config(HttpClientFactoryFactory.class, configPrefix).createClientFactory(injector,
features);
}