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

Java Config类代码示例

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

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



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

示例1: deploy

import org.eclipse.microprofile.config.Config; //导入依赖的package包/类
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    Module module = deploymentUnit.getAttachment(Attachments.MODULE);

    WildFlyConfigBuilder builder = new WildFlyConfigBuilder();
    builder.forClassLoader(module.getClassLoader())
            .addDefaultSources()
            .addDiscoveredSources()
            .addDiscoveredConverters();
    addConfigSourcesFromServices(builder, phaseContext.getServiceRegistry(), module.getClassLoader());
    Config config = builder.build();

    WildFlyConfigProviderResolver.INSTANCE.registerConfig(config, module.getClassLoader());

    if (WeldDeploymentMarker.isPartOfWeldDeployment(deploymentUnit)) {
        WeldPortableExtensions extensions = WeldPortableExtensions.getPortableExtensions(deploymentUnit);
        extensions.registerExtensionInstance(new ConfigExtension(), deploymentUnit);
    }

}
 
开发者ID:wildfly-extras,项目名称:wildfly-microprofile-config,代码行数:22,代码来源:SubsystemDeploymentProcessor.java


示例2: build

import org.eclipse.microprofile.config.Config; //导入依赖的package包/类
@Override
public Config build() {
    if (addDiscoveredSources) {
        sources.addAll(discoverSources());
    }
    if (addDefaultSources) {
        sources.addAll(getDefaultSources());
    }

    if (addDiscoveredConverters) {
        converters.addAll(discoverConverters());
    }

    Collections.sort(sources, new Comparator<ConfigSource>() {
        @Override
        public int compare(ConfigSource o1, ConfigSource o2) {
            return o2.getOrdinal() -  o1.getOrdinal();
        }
    });

    return new WildFlyConfig(sources, converters);
}
 
开发者ID:wildfly-extras,项目名称:wildfly-microprofile-config,代码行数:23,代码来源:WildFlyConfigBuilder.java


示例3: getConfig

import org.eclipse.microprofile.config.Config; //导入依赖的package包/类
private <T> T getValue
        (InjectionPoint injectionPoint, Class<T> target) {
    Config config = getConfig(injectionPoint);
    String name = getName(injectionPoint);
    try {
        if (name == null) {
            return null;
        }
        Optional<T> optionalValue = config.getOptionalValue(name, target);
        if (optionalValue.isPresent()) {
            return optionalValue.get();
        } else {
            String defaultValue = getDefaultValue(injectionPoint);
            if (defaultValue != null) {
                return ((WildFlyConfig)config).convert(defaultValue, target);
            } else {
                return null;
            }
        }
    } catch (RuntimeException e) {
        return null;
    }
}
 
开发者ID:wildfly-extras,项目名称:wildfly-microprofile-config,代码行数:24,代码来源:ConfigProducer.java


示例4: validate

import org.eclipse.microprofile.config.Config; //导入依赖的package包/类
public void validate(@Observes AfterDeploymentValidation add, BeanManager bm) {
    List<String> deploymentProblems = new ArrayList<>();

    Config config = ConfigProvider.getConfig();
    for (InjectionPoint injectionPoint : injectionPoints) {
        Type type = injectionPoint.getType();
        ConfigProperty configProperty = injectionPoint.getAnnotated().getAnnotation(ConfigProperty.class);
        if (type instanceof Class) {
            String key = getConfigKey(injectionPoint, configProperty);

            if (!config.getOptionalValue(key, (Class)type).isPresent()) {
                String defaultValue = configProperty.defaultValue();
                if (defaultValue == null ||
                        defaultValue.equals(ConfigProperty.UNCONFIGURED_VALUE)) {
                    deploymentProblems.add("No Config Value exists for " + key);
                }
            }
        }
    }

    if (!deploymentProblems.isEmpty()) {
        add.addDeploymentProblem(new DeploymentException("Error while validating Configuration\n"
                + String.join("\n", deploymentProblems)));
    }

}
 
开发者ID:wildfly-extras,项目名称:wildfly-microprofile-config,代码行数:27,代码来源:ConfigExtension.java


示例5: testDonaldConversionWithMultipleLambdaConverters

import org.eclipse.microprofile.config.Config; //导入依赖的package包/类
@Test
public void testDonaldConversionWithMultipleLambdaConverters() {
    // defines 2 config with the lambda converters defined in different orders.
    // Order must not matter, the lambda with the upper case must always be used as it has the highest priority
    Config config1 = ConfigProviderResolver.instance().getBuilder().addDefaultSources()
        .withConverter(Donald.class, 101, (s) -> Donald.iLikeDonald(s.toUpperCase()))
        .withConverter(Donald.class, 100, (s) -> Donald.iLikeDonald(s))
        .build();
    Config config2 = ConfigProviderResolver.instance().getBuilder().addDefaultSources()
        .withConverter(Donald.class, 100, (s) -> Donald.iLikeDonald(s))
        .withConverter(Donald.class, 101, (s) -> Donald.iLikeDonald(s.toUpperCase()))
        .build();

    Donald donald = config1.getValue("tck.config.test.javaconfig.converter.donaldname", Donald.class);
    Assert.assertNotNull(donald);
    Assert.assertEquals(donald.getName(), "DUCK",
        "The converter with the highest priority (using upper case) must be used.");
    donald = config2.getValue("tck.config.test.javaconfig.converter.donaldname", Donald.class);
    Assert.assertNotNull(donald);
    Assert.assertEquals(donald.getName(), "DUCK",
        "The converter with the highest priority (using upper case) must be used.");
}
 
开发者ID:eclipse,项目名称:microprofile-config,代码行数:23,代码来源:ConverterTest.java


示例6: testDuckConversionWithMultipleConverters

import org.eclipse.microprofile.config.Config; //导入依赖的package包/类
@Test
public void testDuckConversionWithMultipleConverters() {
    // defines 2 config with the converters defined in different orders.
    // Order must not matter, the UpperCaseDuckConverter must always be used as it has the highest priority
    Config config1 = ConfigProviderResolver.instance().getBuilder().addDefaultSources()
        .withConverters(new UpperCaseDuckConverter(), new DuckConverter())
        .build();
    Config config2 = ConfigProviderResolver.instance().getBuilder().addDefaultSources()
        .withConverters(new DuckConverter(), new UpperCaseDuckConverter())
        .build();

    Duck duck = config1.getValue("tck.config.test.javaconfig.converter.duckname", Duck.class);
    Assert.assertNotNull(duck);
    Assert.assertEquals(duck.getName(), "HANNELORE",
        "The converter with the highest priority (UpperCaseDuckConverter) must be used.");

    duck = config2.getValue("tck.config.test.javaconfig.converter.duckname", Duck.class);
    Assert.assertNotNull(duck);
    // the UpperCaseDuckConverter has highest priority
    Assert.assertEquals(duck.getName(), "HANNELORE",
        "The converter with the highest priority (UpperCaseDuckConverter) must be used.");
}
 
开发者ID:eclipse,项目名称:microprofile-config,代码行数:23,代码来源:ConverterTest.java


示例7: lookup

import org.eclipse.microprofile.config.Config; //导入依赖的package包/类
/**
 * Note that:
 *
 * <pre>
 * If no annotation matches the specified parameter, the property will be ignored.
 * </pre>
 *
 * @param key
 * @param expectedType
 * @return the configured value
 */
private <U> U lookup(String key, Class<U> expectedType) {
    Config config = getConfig();
    Optional<U> value = null;
    if (ElementType.METHOD.equals(annotationSource)) {
        // <classname>/<methodname>/<annotation>/<parameter>
        value = config.getOptionalValue(getConfigKeyForMethod() + key, expectedType);
    } else {
        // <classname>/<annotation>/<parameter>
        value = config.getOptionalValue(getConfigKeyForClass() + key, expectedType);
    }
    if (!value.isPresent()) {
        // <annotation>/<parameter>
        value = config.getOptionalValue(getConfigType().getSimpleName() + "/" + key, expectedType);
    }
    // annotation values
    return value.isPresent() ? value.get() : getConfigFromAnnotation(key);
}
 
开发者ID:wildfly-swarm,项目名称:wildfly-swarm,代码行数:29,代码来源:GenericConfig.java


示例8: releaseConfig

import org.eclipse.microprofile.config.Config; //导入依赖的package包/类
@Override
public void releaseConfig(Config config) {
    if (config == null) {
        // get the config from the current TCCL
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        if (classLoader == null) {
            classLoader = DefaultConfigProvider.class.getClassLoader();
        }
        config = existingConfig(classLoader);
    }

    if (config != null) {
        synchronized (DefaultConfigProvider.class) {
            Iterator<Map.Entry<ClassLoader, WeakReference<Config>>> it = configs.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<ClassLoader, WeakReference<Config>> entry = it.next();
                if (entry.getValue().get() != null && entry.getValue().get() == config) {
                    it.remove();
                    break;
                }
            }
        }
    }
}
 
开发者ID:struberg,项目名称:javaConfig,代码行数:25,代码来源:DefaultConfigProvider.java


示例9: getConfig

import org.eclipse.microprofile.config.Config; //导入依赖的package包/类
@Override
public Config getConfig(ClassLoader classLoader) {
    Config config = configsForClassLoader.get(classLoader);
    if (config != null) {
        return config;
    } else {
        config = getBuilder().forClassLoader(classLoader)
                .addDefaultSources()
                .addDiscoveredSources()
                .addDiscoveredConverters()
                .build();
        registerConfig(config, classLoader);
        return config;
    }
}
 
开发者ID:wildfly-extras,项目名称:wildfly-microprofile-config,代码行数:16,代码来源:WildFlyConfigProviderResolver.java


示例10: releaseConfig

import org.eclipse.microprofile.config.Config; //导入依赖的package包/类
@Override
public void releaseConfig(Config config) {
    Iterator<Map.Entry<ClassLoader, Config>> iterator = configsForClassLoader.entrySet().iterator();
    while (iterator.hasNext()) {
        Map.Entry<ClassLoader, Config> entry = iterator.next();
        if (entry.getValue() == config) {
            iterator.remove();
            return;
        }


    }
}
 
开发者ID:wildfly-extras,项目名称:wildfly-microprofile-config,代码行数:14,代码来源:WildFlyConfigProviderResolver.java


示例11: testDonaldConversionWithLambdaConverter

import org.eclipse.microprofile.config.Config; //导入依赖的package包/类
@Test
public void testDonaldConversionWithLambdaConverter() {
    Config newConfig = ConfigProviderResolver.instance().getBuilder().addDefaultSources()
        .withConverter(Donald.class, 100, (s) -> Donald.iLikeDonald(s))
        .build();
    Donald donald = newConfig.getValue("tck.config.test.javaconfig.converter.donaldname", Donald.class);
    Assert.assertNotNull(donald);
    Assert.assertEquals(donald.getName(), "Duck");
}
 
开发者ID:eclipse,项目名称:microprofile-config,代码行数:10,代码来源:ConverterTest.java


示例12: testAutoDiscoveredConverterManuallyAdded

import org.eclipse.microprofile.config.Config; //导入依赖的package包/类
@Test
public void testAutoDiscoveredConverterManuallyAdded() {

    Config config = ConfigProviderResolver.instance().getBuilder().addDefaultSources().addDiscoveredSources().addDiscoveredConverters().build();
    Pizza dVaule = config.getValue("tck.config.test.customDbConfig.key3", Pizza.class);
    Assert.assertEquals(dVaule.getSize(), "big");
    Assert.assertEquals(dVaule.getFlavor(), "cheese");
}
 
开发者ID:eclipse,项目名称:microprofile-config,代码行数:9,代码来源:AutoDiscoveredConfigSourceTest.java


示例13: build

import org.eclipse.microprofile.config.Config; //导入依赖的package包/类
@Override
public Config build() {
    List<ConfigSource> configSources = new ArrayList<>();
     if (forClassLoader == null) {
         forClassLoader = Thread.currentThread().getContextClassLoader();
         if (forClassLoader == null) {
             forClassLoader = DefaultConfigProvider.class.getClassLoader();
         }
     }

    if (!ignoreDefaultSources) {
        configSources.addAll(getBuiltInConfigSources(forClassLoader));
    }
    configSources.addAll(sources);

    if (!ignoreDiscoveredSources) {
        // load all ConfigSource services
        ServiceLoader<ConfigSource> configSourceLoader = ServiceLoader.load(ConfigSource.class, forClassLoader);
        configSourceLoader.forEach(configSource -> configSources.add(configSource));

        // load all ConfigSources from ConfigSourceProviders
        ServiceLoader<ConfigSourceProvider> configSourceProviderLoader = ServiceLoader.load(ConfigSourceProvider.class, forClassLoader);
        configSourceProviderLoader.forEach(configSourceProvider ->
                configSourceProvider.getConfigSources(forClassLoader)
                        .forEach(configSource -> configSources.add(configSource)));
    }

    ConfigImpl config = new ConfigImpl();
    config.addConfigSources(configSources);

    for (Converter<?> converter : converters) {
        config.addConverter(converter);
    }

    return config;
}
 
开发者ID:struberg,项目名称:javaConfig,代码行数:37,代码来源:DefaultConfigBuilder.java


示例14: getConfig

import org.eclipse.microprofile.config.Config; //导入依赖的package包/类
@Override
public Config getConfig(ClassLoader forClassLoader) {

    Config config = existingConfig(forClassLoader);
    if (config == null) {
        synchronized (DefaultConfigProvider.class) {
            config = existingConfig(forClassLoader);
            if (config == null) {
                config = getBuilder().forClassLoader(forClassLoader).addDefaultSources().addDiscoveredSources().build();
                registerConfig(config, forClassLoader);
            }
        }
    }
    return config;
}
 
开发者ID:struberg,项目名称:javaConfig,代码行数:16,代码来源:DefaultConfigProvider.java


示例15: mapUrls

import org.eclipse.microprofile.config.Config; //导入依赖的package包/类
private static String[] mapUrls(String[] urls) {
    final Config config = ConfigProvider.getConfig();
    List<String> patterns = Arrays.stream(urls)
            .map(s -> {
                if(s.startsWith(PREFIX) && s.endsWith(SUFFIX)) {
                    String key = s.replaceFirst(PREFIX_REGEX,"").replace(SUFFIX,"");
                    return config.getOptionalValue(key, String.class).orElse(s);
                }
                else {
                    return s;
                }
            })
            .collect(toList());
            return patterns.toArray(new String[urls.length]);
}
 
开发者ID:hammock-project,项目名称:hammock,代码行数:16,代码来源:StartWebServer.java


示例16: createConfiguration

import org.eclipse.microprofile.config.Config; //导入依赖的package包/类
private Configuration<HikariDataSource> createConfiguration(String name, Config config, HikariDataSource dataSource) {
    String uniqueId = config.getOptionalValue(format(UNIQUE_ID_PROPERTY_FORMAT, name), String.class).orElse(name);
    Configuration.Builder<HikariDataSource> builder = new Configuration.Builder<>(uniqueId, dataSource, HikariCPPoolAdapter.FACTORY);
    if(metricsFactoryInstance.isResolvable()) {
        MetricsFactory metricsFactory = metricsFactoryInstance.get();
        builder.setMetricsFactory(metricsFactory);
    }
    return builder.build();
}
 
开发者ID:hammock-project,项目名称:hammock,代码行数:10,代码来源:FlexyPoolWrapper.java


示例17: main

import org.eclipse.microprofile.config.Config; //导入依赖的package包/类
public static void main(String... args) {
    ARGS = args;
    Config config = ConfigProvider.getConfig();
    String log4j2Enabled = config.getOptionalValue("enable.log4j2.integration", String.class).orElse(DEFAULT_LOGGING);

    if(DEFAULT_LOGGING.equals(log4j2Enabled)) {
        System.setProperty("java.util.logging.manager","org.apache.logging.log4j.jul.LogManager");
    }
    Bootstrapper bootstrapper = ServiceLoader.load(Bootstrapper.class).iterator().next();
    bootstrapper.start();
}
 
开发者ID:hammock-project,项目名称:hammock,代码行数:12,代码来源:Bootstrap.java


示例18: loadAllProperties

import org.eclipse.microprofile.config.Config; //导入依赖的package包/类
public static Map<String, String> loadAllProperties(String prefix, boolean strip) {
   Config config = ConfigProvider.getConfig();

   Iterable<String> propertyNames = config.getPropertyNames();

   return StreamSupport.stream(propertyNames.spliterator(), false)
      .filter(e -> e.startsWith(prefix))
      .collect(Collectors.toMap(
              new PrefixStripper(strip, prefix),
              s -> config.getValue(s, String.class)));
}
 
开发者ID:hammock-project,项目名称:hammock,代码行数:12,代码来源:ConfigLoader.java


示例19: registerConfig

import org.eclipse.microprofile.config.Config; //导入依赖的package包/类
@Override
public void registerConfig(Config config, ClassLoader classLoader) {
    configsForClassLoader.put(classLoader, config);
}
 
开发者ID:wildfly-extras,项目名称:wildfly-microprofile-config,代码行数:5,代码来源:WildFlyConfigProviderResolver.java


示例20: getConfig

import org.eclipse.microprofile.config.Config; //导入依赖的package包/类
public Config getConfig() {
    if (_config == null) {
        _config = ConfigProvider.getConfig();
    }
    return _config;
}
 
开发者ID:wildfly-extras,项目名称:wildfly-microprofile-config,代码行数:7,代码来源:ConfigInjectionBean.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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