• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ConfigurationFactory类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中io.dropwizard.configuration.ConfigurationFactory的典型用法代码示例。如果您正苦于以下问题:Java ConfigurationFactory类的具体用法?Java ConfigurationFactory怎么用?Java ConfigurationFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ConfigurationFactory类属于io.dropwizard.configuration包,在下文中一共展示了ConfigurationFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getConfiguration

import io.dropwizard.configuration.ConfigurationFactory; //导入依赖的package包/类
@Override
public RestlerConfig getConfiguration()  {
    ObjectMapper objectMapper = Jackson.newObjectMapper();

    ValidatorFactory validatorFactory = Validation
            .byProvider(HibernateValidator.class)
            .configure()
            .addValidatedValueHandler(new OptionalValidatedValueUnwrapper())
            .buildValidatorFactory();


    final ConfigurationFactory<RestlerConfig> configurationFactory =
            new DefaultConfigurationFactoryFactory<RestlerConfig>().create(RestlerConfig.class, validatorFactory.getValidator(), objectMapper, "dw");

    try {
        return configurationFactory.build(new FileConfigurationSourceProvider(), TEST_CONFIG_FILE);
    } catch (Exception e) {
        throw new RuntimeException("Cannot get test configuration", e);
    }
}
 
开发者ID:researchgate,项目名称:restler,代码行数:21,代码来源:TestRestlerModule.java


示例2: beforeAll

import io.dropwizard.configuration.ConfigurationFactory; //导入依赖的package包/类
@Before
public void beforeAll() throws Exception {
    server = new TestingServer();
    server.start();
    Capabilities mockCapabilities = Mockito.mock(Capabilities.class);
    when(mockCapabilities.supportsNamedVips()).thenReturn(true);
    taskFactory = new CassandraDaemonTask.Factory(mockCapabilities);
    configurationFactory = new ConfigurationFactory<>(
                    MutableSchedulerConfiguration.class,
                    BaseValidator.newValidator(),
                    Jackson.newObjectMapper()
                            .registerModule(new GuavaModule())
                            .registerModule(new Jdk8Module()),
                    "dw");
    connectString = server.getConnectString();
}
 
开发者ID:mesosphere,项目名称:dcos-cassandra-service,代码行数:17,代码来源:ConfigurationManagerTest.java


示例3: apply

import io.dropwizard.configuration.ConfigurationFactory; //导入依赖的package包/类
@Override public Statement apply(final Statement base, Description description) {
  return new Statement() {
    @Override public void evaluate() throws Throwable {
      File yamlFile = new File(Resources.getResource("keywhiz-test.yaml").getFile());
      Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
      ObjectMapper objectMapper = KeywhizService.customizeObjectMapper(Jackson.newObjectMapper());
      KeywhizConfig config = new ConfigurationFactory<>(KeywhizConfig.class, validator, objectMapper, "dw")
          .build(yamlFile);

      DataSource dataSource = config.getDataSourceFactory()
          .build(new MetricRegistry(), "db-migrations");

      Flyway flyway = new Flyway();
      flyway.setDataSource(dataSource);
      flyway.setLocations(config.getMigrationsDir());
      flyway.clean();
      flyway.migrate();

      DSLContext dslContext = DSLContexts.databaseAgnostic(dataSource);
      DbSeedCommand.doImport(dslContext);

      base.evaluate();
    }
  };
}
 
开发者ID:square,项目名称:keywhiz,代码行数:26,代码来源:MigrationsRule.java


示例4: initialize

import io.dropwizard.configuration.ConfigurationFactory; //导入依赖的package包/类
@Override
public void initialize(Bootstrap<?> bootstrap)
{
    final InjectableValues injectableValues = new InjectableValues()
    {
        @Override
        public Object findInjectableValue(Object valueId, DeserializationContext ctxt, BeanProperty forProperty, Object beanInstance)
        {
            return null;
        }
    };
    final ConfigurationFactoryFactory<? extends Configuration> configurationFactoryFactory = bootstrap.getConfigurationFactoryFactory();
    ConfigurationFactoryFactory factoryFactory = new ConfigurationFactoryFactory()
    {
        @Override
        public ConfigurationFactory create(Class klass, Validator validator, ObjectMapper objectMapper, String propertyPrefix)
        {
            objectMapper.setInjectableValues(injectableValues);
            //noinspection unchecked
            return configurationFactoryFactory.create(klass, validator, objectMapper, propertyPrefix);
        }
    };
    //noinspection unchecked
    bootstrap.setConfigurationFactoryFactory(factoryFactory);
}
 
开发者ID:soabase,项目名称:soabase,代码行数:26,代码来源:GuiceBundle.java


示例5: testParsing

import io.dropwizard.configuration.ConfigurationFactory; //导入依赖的package包/类
@Test
public void testParsing() throws Exception {
    ConfigurationFactory<MacroBaseConf> cfFactory = new ConfigurationFactory<>(MacroBaseConf.class,
                                                                               null,
                                                                               Jackson.newObjectMapper(),
                                                                               "");
    MacroBaseConf conf = cfFactory.build(new File("src/test/resources/conf/simple.yaml"));


    assertEquals((Double) 0.1, conf.getDouble("this.is.a.double"));
    assertEquals((Integer) 100, conf.getInt("this.is.an.integer"));
    assertEquals((Long) 10000000000000L, conf.getLong("this.is.a.long"));
    assertEquals("Test", conf.getString("this.is.a.string"));

    List<String> stringList = Lists.newArrayList("T1", "T2", "T3", "T4");
    assertArrayEquals(stringList.toArray(), conf.getStringList("this.is.a.stringList").toArray());
    assertArrayEquals(stringList.toArray(), conf.getStringList("this.is.a.stringList.without.spaces").toArray());
    assertArrayEquals(stringList.toArray(), conf.getStringList("this.is.a.stringList.with.mixed.spaces").toArray());
}
 
开发者ID:stanford-futuredata,项目名称:macrobase,代码行数:20,代码来源:MacroBaseConfTest.java


示例6: buildFromFile

import io.dropwizard.configuration.ConfigurationFactory; //导入依赖的package包/类
/**
 * Builds a Configuration object from the file path given. It uses the {@link io.dropwizard.configuration.ConfigurationFactory}
 * to build the configuration.
 *
 * @param possibleFilename The path to the configuration.
 * @return A configuration object loaded form the filename given.
 */
private Config buildFromFile(String possibleFilename) {
    File configFile = new File(possibleFilename);
    Preconditions.checkArgument(configFile.exists(), "File must exist at: " + configFile.getAbsolutePath());

    try {
        return new ConfigurationFactory<>(
                configClass,
                Validation.buildDefaultValidatorFactory().getValidator(),
                Jackson.newObjectMapper(),
                "graceland")
                .build(configFile);

    } catch (Exception e) {
        String msg = "Unknown exception triggered when attempting to build config from file:" + "\n" +
                "\t* Configuration Class: " + configClass.getCanonicalName() + "\n" +
                "\t* File: " + configFile.getAbsolutePath();

        throw new RuntimeException(msg, e);
    }
}
 
开发者ID:graceland,项目名称:graceland-core,代码行数:28,代码来源:ConfigurationBinder.java


示例7: createConfiguration

import io.dropwizard.configuration.ConfigurationFactory; //导入依赖的package包/类
public static OregamiConfiguration createConfiguration(String configFilename) {
    ConfigurationFactory<OregamiConfiguration> factory =
            new ConfigurationFactory<>(
                    OregamiConfiguration.class,
                    Validation.buildDefaultValidatorFactory().getValidator(),
                    Jackson.newObjectMapper(),
                    ""
            );
    OregamiConfiguration configuration;
    try {
        configuration = factory.build(new File(configFilename));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    System.out.println(ToStringBuilder.reflectionToString(configuration, ToStringStyle.MULTI_LINE_STYLE));
    System.out.println(ToStringBuilder.reflectionToString(configuration.getDatabaseConfiguration(), ToStringStyle.MULTI_LINE_STYLE));
    return configuration;
}
 
开发者ID:oregami,项目名称:oregami-server,代码行数:19,代码来源:StartHelper.java


示例8: loadSupportedMsaVersions

import io.dropwizard.configuration.ConfigurationFactory; //导入依赖的package包/类
public SupportedMsaVersions loadSupportedMsaVersions(final URL url) {
    final ConfigurationFactory<SupportedMsaVersions> factory = supportedMsaVersionsFactoryFactory.create(
            SupportedMsaVersions.class,
            buildDefaultValidatorFactory().getValidator(),
            objectMapper,
            "");
    try {
        SupportedMsaVersions supportedMsaVersions = factory.build(
                configurationSourceProvider,
                url.toString());
        return supportedMsaVersions;
    } catch (IOException | ConfigurationException e) {
        throw propagate(e);
    }
}
 
开发者ID:alphagov,项目名称:verify-hub,代码行数:16,代码来源:SupportedMsaVersionsLoader.java


示例9: FileBackedConfigDataSource

import io.dropwizard.configuration.ConfigurationFactory; //导入依赖的package包/类
public FileBackedConfigDataSource(
        ConfigConfiguration configuration,
        ConfigurationFactory<T> configurationFactory,
        String dataDirectory) {

    this.configuration = configuration;
    this.configurationFactory = configurationFactory;
    this.dataDirectory = dataDirectory;
}
 
开发者ID:alphagov,项目名称:verify-hub,代码行数:10,代码来源:FileBackedConfigDataSource.java


示例10: beforeEach

import io.dropwizard.configuration.ConfigurationFactory; //导入依赖的package包/类
@Before
public void beforeEach() throws Exception {
  factory = new ConfigurationFactory<>(
    MutableSchedulerConfiguration.class,
    BaseValidator.newValidator(),
    Jackson.newObjectMapper().registerModule(new GuavaModule())
      .registerModule(new Jdk8Module()),
    "dw");

  configuration = factory.build(
    new SubstitutingSourceProvider(
      new FileConfigurationSourceProvider(),
      new EnvironmentVariableSubstitutor(false, true)),
    Resources.getResource("scheduler.yml").getFile());
}
 
开发者ID:mesosphere,项目名称:dcos-cassandra-service,代码行数:16,代码来源:ConfigValidatorTest.java


示例11: loadConfigFile

import io.dropwizard.configuration.ConfigurationFactory; //导入依赖的package包/类
private EmoConfiguration loadConfigFile(File configFile)
        throws IOException, ConfigurationException {
    Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
    ObjectMapper mapper = CustomJsonObjectMapperFactory.build(new YAMLFactory());
    ConfigurationFactory<EmoConfiguration> configurationFactory = new ConfigurationFactory(EmoConfiguration.class, validator, mapper, "dw");
    return configurationFactory.build(configFile);
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:8,代码来源:EmoService.java


示例12: getConfigurationFromResource

import io.dropwizard.configuration.ConfigurationFactory; //导入依赖的package包/类
protected EmoConfiguration getConfigurationFromResource()  throws Exception {
    URL url = BaseRoleConnectHelper.class.getResource(_configFileResource);
    Preconditions.checkNotNull(url, _configFileResource);
    File file = new File (url.toURI());
    Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
    ObjectMapper mapper = CustomJsonObjectMapperFactory.build(new YAMLFactory());

    ConfigurationFactory<EmoConfiguration> configFactory = new ConfigurationFactory<>(EmoConfiguration.class, validator, mapper, "dw");
    return configFactory.build(file);
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:11,代码来源:BaseRoleConnectHelper.java


示例13: ensureSdkDefaultConfigDeserialization

import io.dropwizard.configuration.ConfigurationFactory; //导入依赖的package包/类
@Test
public void ensureSdkDefaultConfigDeserialization()
        throws IOException, URISyntaxException, ConfigurationException {
    // This test makes sure that we haven't forgotten to update the emodb sdk default config file when we add/remove properties
    Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
    ObjectMapper mapper = CustomJsonObjectMapperFactory.build(new YAMLFactory());
    ConfigurationFactory configurationFactory = new ConfigurationFactory(EmoConfiguration.class, validator, mapper, "dw");
    // Make sure that our config files are up to date
    configurationFactory.build(
    new File(EmoStartMojo.class.getResource("/emodb-default-config.yaml").toURI()));
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:12,代码来源:SdkConfigTest.java


示例14: create

import io.dropwizard.configuration.ConfigurationFactory; //导入依赖的package包/类
@Override
public ConfigurationFactory<T> create(
    final Class<T> klass,
    final Validator validator,
    final ObjectMapper objectMapper,
    final String propertyPrefix
) {
    return new ImportableConfigurationFactory<T>(
        klass,
        validator,
        configureObjectMapper(objectMapper.copy()),
        propertyPrefix
    );
}
 
开发者ID:vvondra,项目名称:dropwizard-config-importable,代码行数:15,代码来源:ImportableConfigurationFactoryFactory.java


示例15: parse

import io.dropwizard.configuration.ConfigurationFactory; //导入依赖的package包/类
/**
 * Parses the given configuration file and returns a configuration object.
 *
 * @param configurationFileName The name of the configuration file.
 * @return A configuration object.
 * @throws IOException The IO error that contains detail information.
 * @throws ConfigurationException The configuration error that contains detail information.
 */
public static ApiConfiguration parse(String configurationFileName)
  throws IOException, ConfigurationException {
  if (StringUtils.isBlank(configurationFileName)) {
    throw new IllegalArgumentException("Configuration file cannot be blank");
  }

  ObjectMapper objectMapper = null;
  if (configurationFileName.endsWith("yml") || configurationFileName.endsWith("yaml")) {
    objectMapper = Jackson.newObjectMapper(new YAMLFactory());
  } else if (configurationFileName.endsWith("json")) {
    objectMapper = Jackson.newObjectMapper(new JsonFactory());
  } else {
    throw new IllegalArgumentException("Unrecognized configuration file type");
  }

  ValidatorFactory validatorFactory = Validation
      .byProvider(HibernateValidator.class)
      .configure()
      .addValidatedValueHandler(new OptionalValidatedValueUnwrapper())
      .buildValidatorFactory();

  final ConfigurationFactory<ApiConfiguration> configurationFactory =
      new DefaultConfigurationFactoryFactory<ApiConfiguration>()
        .create(ApiConfiguration.class, validatorFactory.getValidator(), objectMapper, "dw");

  final File file = new File(configurationFileName);
  if (!file.exists()) {
    throw new FileNotFoundException("Configuration file " + configurationFileName + " not found");
  }

  return configurationFactory.build(file);
}
 
开发者ID:zeelichsheng,项目名称:auth,代码行数:41,代码来源:ConfigurationParser.java


示例16: parsesLDAPLookupCorrectly

import io.dropwizard.configuration.ConfigurationFactory; //导入依赖的package包/类
@Test public void parsesLDAPLookupCorrectly() throws Exception {
  File yamlFile = new File(Resources.getResource("fixtures/keywhiz-ldap-lookup-test.yaml").getFile());
  Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
  ObjectMapper objectMapper = bootstrap.getObjectMapper().copy();

  LdapLookupConfig lookupConfig =
      new ConfigurationFactory<>(LdapLookupConfig.class, validator, objectMapper, "dw")
          .build(yamlFile);

  assertThat(lookupConfig.getRequiredRoles()).containsOnly("keywhizAdmins");
  assertThat(lookupConfig.getRoleBaseDN()).isEqualTo("ou=ApplicationAccess,dc=test,dc=com");
  assertThat(lookupConfig.getUserBaseDN()).isEqualTo("ou=people,dc=test,dc=com");
  assertThat(lookupConfig.getUserAttribute()).isEqualTo("uid");
}
 
开发者ID:square,项目名称:keywhiz,代码行数:15,代码来源:LdapLookupConfigTest.java


示例17: createInjector

import io.dropwizard.configuration.ConfigurationFactory; //导入依赖的package包/类
static Injector createInjector() {
  KeywhizService service = new KeywhizService();
  Bootstrap<KeywhizConfig> bootstrap = new Bootstrap<>(service);
  service.initialize(bootstrap);

  File yamlFile = new File(Resources.getResource("keywhiz-test.yaml").getFile());
  Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
  ObjectMapper objectMapper = bootstrap.getObjectMapper().copy();
  KeywhizConfig config;
  try {
    config = new ConfigurationFactory<>(KeywhizConfig.class, validator, objectMapper, "dw")
        .build(yamlFile);
  } catch (IOException | ConfigurationException e) {
    throw Throwables.propagate(e);
  }

  Environment environment = new Environment(service.getName(),
      objectMapper,
      validator,
      bootstrap.getMetricRegistry(),
      bootstrap.getClassLoader());

  Injector injector = Guice.createInjector(new ServiceModule(config, environment));

  service.setInjector(injector);
  return injector;
}
 
开发者ID:square,项目名称:keywhiz,代码行数:28,代码来源:KeywhizTestRunner.java


示例18: testViaDW

import io.dropwizard.configuration.ConfigurationFactory; //导入依赖的package包/类
@Test
public void testViaDW() throws Exception
{
    Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
    ObjectMapper objectMapper = Jackson.newObjectMapper();
    ConfigurationFactory<MyConfiguration> configurationFactory = new DefaultConfigurationFactoryFactory<MyConfiguration>().create(MyConfiguration.class, validator, objectMapper, "dw");
    MyConfiguration configuration = configurationFactory.build(new FlexibleConfigurationSourceProvider(), "%{\"testValue\": \"override\"}");
    Assert.assertEquals("override", configuration.testValue);
}
 
开发者ID:soabase,项目名称:soabase,代码行数:10,代码来源:TestFlexibleConfigurationSourceProvider.java


示例19: withConfigurationClass

import io.dropwizard.configuration.ConfigurationFactory; //导入依赖的package包/类
public AdminConsoleAppBuilder<T> withConfigurationClass(final Class<T> configurationClass)
{
    factoryFactory = new ConfigurationFactoryFactory<T>()
    {
        @Override
        public ConfigurationFactory<T> create(Class<T> klass, Validator validator, ObjectMapper objectMapper, String propertyPrefix)
        {
            return new YamlConfigurationFactory<>(configurationClass, validator, objectMapper, propertyPrefix);
        }
    };
    return this;
}
 
开发者ID:soabase,项目名称:soabase,代码行数:13,代码来源:AdminConsoleAppBuilder.java


示例20: setupTest

import io.dropwizard.configuration.ConfigurationFactory; //导入依赖的package包/类
@Before
public void setupTest() throws Exception {
    azureTableConfiguration = new ConfigurationFactory<>(
            AzureTableConfiguration.class,
            Validation.buildDefaultValidatorFactory().getValidator(),
            Jackson.newObjectMapper(),
            "dw.").build(new File(Resources.getResource("azure-test.yml").toURI()));
}
 
开发者ID:guggens,项目名称:log-dropwizard-eureka-mongo-sample,代码行数:9,代码来源:WithConfiguration.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SplitParentFirstComparator类代码示例发布时间:2022-05-21
下一篇:
Java Range类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap