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


Java Configuration类代码示例

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


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

示例1: onStartup

import org.apache.commons.configuration.Configuration; //导入依赖的package包/类
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
  if (getPort() == 0) {
    LOGGER.warn(
        "spring boot embed web container listen port is 0, serviceComb will not use container's port to handler RESTful request.");
    return;
  }

  // web container did not did listen now.
  // so mock to listen, and then close.
  try (ServerSocket ss = new ServerSocket(getPort(), 0, getAddress())) {
    if (StringUtils.isEmpty(ServletConfig.getServletUrlPattern())) {
      // ensure the servlet will be instantiated
      Configuration configuration = (Configuration) DynamicPropertyFactory.getBackingConfigurationSource();
      configuration.setProperty(ServletConfig.KEY_SERVLET_URL_PATTERN, ServletConfig.DEFAULT_URL_PATTERN);
    }
    RestServletInjector.defaultInject(servletContext);
    ServletUtils.saveUrlPrefix(servletContext);
  } catch (IOException e) {
    throw new ServletException(e);
  }
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:23,代码来源:RestServletInitializer.java

示例2: testOnStartup

import org.apache.commons.configuration.Configuration; //导入依赖的package包/类
@Test
public void testOnStartup() throws Exception {
  Configuration configuration = (Configuration) DynamicPropertyFactory.getBackingConfigurationSource();
  String urlPattern = "/rest/*";
  configuration.setProperty(ServletConfig.KEY_SERVLET_URL_PATTERN, urlPattern);

  ServletContext servletContext = mock(ServletContext.class);
  Dynamic dynamic = mock(Dynamic.class);
  when(servletContext.addServlet(RestServletInjector.SERVLET_NAME, RestServlet.class)).thenReturn(dynamic);

  RestServletInitializer restServletInitializer = new RestServletInitializer();
  restServletInitializer.setPort(TEST_PORT);
  restServletInitializer.onStartup(servletContext);

  verify(dynamic).setAsyncSupported(true);
  verify(dynamic).addMapping(urlPattern);
  verify(dynamic).setLoadOnStartup(0);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:19,代码来源:TestRestServletInitializer.java

示例3: getMicroserviceVersionFactory

import org.apache.commons.configuration.Configuration; //导入依赖的package包/类
@Test
public void getMicroserviceVersionFactory() {
  DynamicPropertyFactory.getInstance();
  Configuration config = (Configuration) DynamicPropertyFactory.getBackingConfigurationSource();
  config.addProperty(ServiceRegistryConfig.MICROSERVICE_VERSION_FACTORY, "test");

  Assert.assertEquals("test", ServiceRegistryConfig.INSTANCE.getMicroserviceVersionFactory());

  config.clearProperty(ServiceRegistryConfig.MICROSERVICE_VERSION_FACTORY);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:11,代码来源:TestServiceRegistryConfig.java

示例4: onBootEvent

import org.apache.commons.configuration.Configuration; //导入依赖的package包/类
@Override
public void onBootEvent(BootEvent event) {
  if (!EventType.BEFORE_PRODUCER_PROVIDER.equals(event.getEventType())) {
    return;
  }

  String defaultExecutor = DynamicPropertyFactory.getInstance()
      .getStringProperty(ExecutorManager.KEY_EXECUTORS_DEFAULT, null)
      .get();
  if (defaultExecutor != null) {
    LOGGER.info("Edge service default executor is {}.", defaultExecutor);
    return;
  }

  // change default to reactive mode
  Configuration configuration = (Configuration) DynamicPropertyFactory.getBackingConfigurationSource();
  configuration.setProperty(ExecutorManager.KEY_EXECUTORS_DEFAULT, ExecutorManager.EXECUTOR_REACTIVE);
  LOGGER.info("Set ReactiveExecutor to be edge service default executor.");
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:20,代码来源:EdgeBootListener.java

示例5: testGetServletUrlPattern

import org.apache.commons.configuration.Configuration; //导入依赖的package包/类
@Test
public void testGetServletUrlPattern() {
  DynamicPropertyFactory.getInstance();
  Configuration configuration = (Configuration) DynamicPropertyFactory.getBackingConfigurationSource();
  configuration.setProperty(ServletConfig.KEY_SERVLET_URL_PATTERN, "/*");
  Assert.assertEquals("/*", ServletConfig.getServletUrlPattern());
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:8,代码来源:TestServletConfig.java

示例6: parseFromProperties

import org.apache.commons.configuration.Configuration; //导入依赖的package包/类
public static MutableCollection<DbMergeInfo> parseFromProperties(Configuration config) {
    Set<String> dbs = new HashSet<String>(config.getList("instances"));

    MutableList<DbMergeInfo> dbMergeInfos = Lists.mutable.empty();
    for (String db : dbs) {
        Configuration subset = config.subset(db);
        if (subset.containsKey("inputDir")) {
            File inputDir = new File(subset.getString("inputDir"));
            DbMergeInfo mergeInfo = new DbMergeInfo(db, inputDir);
            if (subset.containsKey("driverClassName")) {
                mergeInfo.setDriverClassName(subset.getString("driverClassName"));
                mergeInfo.setUrl(subset.getString("url"));
                mergeInfo.setUsername(subset.getString("username"));
                mergeInfo.setPassword(subset.getString("password"));
                mergeInfo.setPhysicalSchema(subset.getString("physicalSchema"));
            }

            dbMergeInfos.add(mergeInfo);
        }
    }

    return dbMergeInfos;
}
 
开发者ID:goldmansachs,项目名称:obevo,代码行数:24,代码来源:DbMergeInfo.java

示例7: getAsciiDocOptionsAndAttributes

import org.apache.commons.configuration.Configuration; //导入依赖的package包/类
private Options getAsciiDocOptionsAndAttributes(ParserContext context) {
    Configuration config = context.getConfig();
    final AttributesBuilder attributes = attributes(config.getStringArray(Keys.ASCIIDOCTOR_ATTRIBUTES));
    if (config.getBoolean(Keys.ASCIIDOCTOR_ATTRIBUTES_EXPORT, false)) {
        final String prefix = config.getString(  Keys.ASCIIDOCTOR_ATTRIBUTES_EXPORT_PREFIX, "");
        for (final Iterator<String> it = config.getKeys(); it.hasNext();) {
            final String key = it.next();
            if (!key.startsWith("asciidoctor")) {
                attributes.attribute(prefix + key.replace(".", "_"), config.getProperty(key));
            }
        }
    }
    final Configuration optionsSubset = config.subset(Keys.ASCIIDOCTOR_OPTION);
    final Options options = options().attributes(attributes.get()).get();
    for (final Iterator<String> iterator = optionsSubset.getKeys(); iterator.hasNext();) {
        final String name = iterator.next();
        if (name.equals(Options.TEMPLATE_DIRS)) {
        	options.setTemplateDirs(optionsSubset.getString(name));
        } else {
        	options.setOption(name,  guessTypeByContent(optionsSubset.getString(name)));
        }
    }
    options.setBaseDir(context.getFile().getParentFile().getAbsolutePath());
    options.setSafe(UNSAFE);
    return options;
}
 
开发者ID:ghaseminya,项目名称:jbake-rtl-jalaali,代码行数:27,代码来源:AsciidoctorEngine.java

示例8: loadEngines

import org.apache.commons.configuration.Configuration; //导入依赖的package包/类
/**
 * This method is used internally to load markup engines. Markup engines are found using descriptor files on
 * classpath, so adding an engine is as easy as adding a jar on classpath with the descriptor file included.
 */
private void loadEngines(final Configuration config, final ContentStore db, final File destination, final File templatesPath) {
    try {
        ClassLoader cl = TemplateEngines.class.getClassLoader();
        Enumeration<URL> resources = cl.getResources("META-INF/org.jbake.parser.TemplateEngines.properties");
        while (resources.hasMoreElements()) {
            URL url = resources.nextElement();
            Properties props = new Properties();
            props.load(url.openStream());
            for (Map.Entry<Object, Object> entry : props.entrySet()) {
                String className = (String) entry.getKey();
                String[] extensions = ((String) entry.getValue()).split(",");
                registerEngine(config, db, destination, templatesPath, className, extensions);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:ghaseminya,项目名称:jbake-rtl-jalaali,代码行数:23,代码来源:TemplateEngines.java

示例9: setUp

import org.apache.commons.configuration.Configuration; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
  Configuration configuration = (Configuration) DynamicPropertyFactory.getBackingConfigurationSource();
  configuration.clearProperty(ServletConfig.KEY_SERVLET_URL_PATTERN);
  configuration.setProperty(ServletConfig.KEY_CSE_REST_ADDRESS, LISTEN_ADDRESS);

  PowerMockito.mockStatic(NetUtils.class);
  PowerMockito.when(NetUtils.parseIpPortFromURI(anyString())).thenReturn(new IpPort(LISTEN_ADDRESS, TEST_PORT));
  PowerMockito.when(NetUtils.canTcpListen(anyObject(), anyInt())).thenReturn(false);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:11,代码来源:TestRestServletInitializer.java

示例10: setProperty

import org.apache.commons.configuration.Configuration; //导入依赖的package包/类
public static void setProperty(String key, Object value) {
  // ensure have instance
  DynamicPropertyFactory.getInstance();
  Configuration config = (Configuration) DynamicPropertyFactory.getBackingConfigurationSource();
  config.addProperty(key, value);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:7,代码来源:ArchaiusUtils.java

示例11: createConfigFromConfigCenter

import org.apache.commons.configuration.Configuration; //导入依赖的package包/类
public static DynamicWatchedConfiguration createConfigFromConfigCenter(Configuration localConfiguration) {
  if (localConfiguration.getProperty(configCenterUrlKey) == null) {
    LOGGER.info("config center URL is missing, skip to load configuration from config center");
    return null;
  }

  ConfigCenterConfigurationSource configCenterConfigurationSource =
      SPIServiceUtils.getTargetService(ConfigCenterConfigurationSource.class);
  if (null == configCenterConfigurationSource) {
    LOGGER.info(
        "config center SPI service can not find, skip to load configuration from config center");
    return null;
  }

  configCenterConfigurationSource.init(localConfiguration);
  return new DynamicWatchedConfiguration(configCenterConfigurationSource);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:18,代码来源:ConfigUtil.java

示例12: testAll

import org.apache.commons.configuration.Configuration; //导入依赖的package包/类
@Test
public void testAll() {
  ConfigurationSpringInitializer configurationSpringInitializer = new ConfigurationSpringInitializer();

  Assert.assertEquals(Ordered.LOWEST_PRECEDENCE / 2, configurationSpringInitializer.getOrder());
  Assert.assertEquals(true,
      Deencapsulation.getField(configurationSpringInitializer, "ignoreUnresolvablePlaceholders"));

  Object o = ConfigUtil.getProperty("zq");
  @SuppressWarnings("unchecked")
  List<Map<String, Object>> listO = (List<Map<String, Object>>) o;
  Assert.assertEquals(3, listO.size());
  Assert.assertEquals(null, ConfigUtil.getProperty("notExist"));

  MicroserviceConfigLoader loader = ConfigUtil.getMicroserviceConfigLoader();
  Assert.assertNotNull(loader);

  Configuration instance = ConfigurationManager.getConfigInstance();
  ConfigUtil.installDynamicConfig();
  // must not reinstall
  Assert.assertEquals(instance, ConfigurationManager.getConfigInstance());
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:23,代码来源:TestConfigurationSpringInitializer.java

示例13: getPropertiesWithPrefix

import org.apache.commons.configuration.Configuration; //导入依赖的package包/类
/**
 * 获取key包含prefix前缀的所有配置项
 */
public static Map<String, String> getPropertiesWithPrefix(String prefix) {
  Object config = DynamicPropertyFactory.getBackingConfigurationSource();
  if (!Configuration.class.isInstance(config)) {
    return new HashMap<>();
  }

  return getPropertiesWithPrefix((Configuration) config, prefix);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:12,代码来源:ConfigurePropertyUtils.java

示例14: testGetPropertiesWithPrefix

import org.apache.commons.configuration.Configuration; //导入依赖的package包/类
@Test
public void testGetPropertiesWithPrefix() {
  Configuration configuration = ConfigUtil.createLocalConfig();

  String prefix = "service_description.properties";
  Map<String, String> expectedMap = new HashMap<>();
  expectedMap.put("key1", "value1");
  expectedMap.put("key2", "value2");
  Assert.assertEquals(expectedMap, ConfigurePropertyUtils.getPropertiesWithPrefix(configuration, prefix));

  List<BasePath> paths = ConfigurePropertyUtils.getMicroservicePaths(configuration);
  Assert.assertEquals(2, paths.size());
  Assert.assertEquals(paths.get(0).getPath(), "/test1/testpath");
  Assert.assertEquals(paths.get(0).getProperty().get("checksession"), false);

  System.setProperty(Const.URL_PREFIX, "/webroot");
  paths = ConfigurePropertyUtils.getMicroservicePaths(configuration);
  Assert.assertEquals(2, paths.size());
  Assert.assertEquals(paths.get(0).getPath(), "/webroot/test1/testpath");
  Assert.assertEquals(paths.get(0).getProperty().get("checksession"), false);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:22,代码来源:TestConfigurePropertyUtils.java

示例15: loadFirst

import org.apache.commons.configuration.Configuration; //导入依赖的package包/类
/**
 * Load configuration from a list of files until the first successful load
 * @param conf  the configuration object
 * @param files the list of filenames to try
 * @return  the configuration object
 */
static MetricsConfig loadFirst(String prefix, String... fileNames) {
  for (String fname : fileNames) {
    try {
      Configuration cf = new PropertiesConfiguration(fname)
          .interpolatedConfiguration();
      LOG.info("loaded properties from "+ fname);
      LOG.debug(toString(cf));
      MetricsConfig mc = new MetricsConfig(cf, prefix);
      LOG.debug(mc);
      return mc;
    } catch (ConfigurationException e) {
      if (e.getMessage().startsWith("Cannot locate configuration")) {
        continue;
      }
      throw new MetricsConfigException(e);
    }
  }
  LOG.warn("Cannot locate configuration: tried "+
           Joiner.on(",").join(fileNames));
  // default to an empty configuration
  return new MetricsConfig(new PropertiesConfiguration(), prefix);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:29,代码来源:MetricsConfig.java


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