当前位置: 首页>>代码示例>>Java>>正文


Java ConfigurationFactory类代码示例

本文整理汇总了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");
}
 
开发者ID:bootique,项目名称:bootique,代码行数:19,代码来源:BQTestFactoryIT.java

示例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);
}
 
开发者ID:bootique,项目名称:bootique,代码行数:22,代码来源:BQCoreModule.java

示例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);
}
 
开发者ID:bootique,项目名称:bootique,代码行数:18,代码来源:JsonNodeConfigurationFactoryProvider.java

示例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"));
}
 
开发者ID:bootique,项目名称:bootique,代码行数:24,代码来源:Bootique_ConfigurationIT.java

示例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"));
}
 
开发者ID:bootique,项目名称:bootique,代码行数:21,代码来源:Bootique_ConfigurationIT.java

示例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);
}
 
开发者ID:bootique,项目名称:bootique,代码行数:19,代码来源:Bootique_ConfigurationIT.java

示例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");
    }
}
 
开发者ID:bootique,项目名称:bootique,代码行数:20,代码来源:Bootique_CliOptionsIT.java

示例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);
}
 
开发者ID:bootique,项目名称:bootique,代码行数:27,代码来源:JsonNodeConfigurationFactoryProviderTest.java

示例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;
}
 
开发者ID:bootique,项目名称:bootique-jdbc,代码行数:22,代码来源:JdbcModule.java

示例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());
}
 
开发者ID:bootique,项目名称:bootique-logback,代码行数:26,代码来源:LogbackContextFactoryIT.java

示例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;
}
 
开发者ID:bootique,项目名称:bootique-metrics,代码行数:16,代码来源:HealthCheckModule.java

示例12: provideJooqFactory

import io.bootique.config.ConfigurationFactory; //导入依赖的package包/类
@Provides
@Singleton
JooqFactory provideJooqFactory(ConfigurationFactory configurationFactory, DataSourceFactory dataSourceFactory) {
    return configurationFactory
            .config(DefaultJooqFactoryFactory.class, configPrefix)
            .createFactory(dataSourceFactory);
}
 
开发者ID:bootique,项目名称:bootique-jooq,代码行数:8,代码来源:JooqModule.java

示例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);
}
 
开发者ID:bootique,项目名称:bootique-shiro,代码行数:8,代码来源:ShiroModule.java

示例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);
}
 
开发者ID:bootique,项目名称:bootique-shiro,代码行数:11,代码来源:ShiroWebModule.java

示例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);
}
 
开发者ID:bootique,项目名称:bootique-jersey-client,代码行数:8,代码来源:JerseyClientModule.java


注:本文中的io.bootique.config.ConfigurationFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。