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


Java ConfigurationFactory类代码示例

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


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


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