本文整理汇总了Java中org.eclipse.microprofile.config.Config类的典型用法代码示例。如果您正苦于以下问题:Java Config类的具体用法?Java Config怎么用?Java Config使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Config类属于org.eclipse.microprofile.config包,在下文中一共展示了Config类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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;
}
}
示例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)));
}
}
示例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.");
}
示例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.");
}
示例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);
}
示例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;
}
}
}
}
}
示例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");
}
示例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");
}
示例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;
}
示例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;
}
示例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]);
}