use of org.springframework.core.env.Environment in project pinpoint by naver.
the class ExperimentalConfig method readExperimentalProperties.
private Map<String, Object> readExperimentalProperties(Environment environment) {
MutablePropertySources propertySources = ((AbstractEnvironment) environment).getPropertySources();
Map<String, Object> collect = propertySources.stream().filter(ps -> ps instanceof EnumerablePropertySource).map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).filter(propName -> propName.startsWith(PREFIX)).collect(Collectors.toMap(Function.identity(), toValue(environment)));
return collect;
}
use of org.springframework.core.env.Environment in project yyl_example by Relucent.
the class SpringExpressionLanguageExample method main.
public static void main(String[] args) {
ExpressionParser parser = new SpelExpressionParser();
Environment environment = getEnvironment();
RootBean root = new RootBean(environment);
StandardEvaluationContext context = new StandardEvaluationContext(root);
context.setVariable("environment", environment);
Expression expression = parser.parseExpression("environment.getProperty('demo.message')");
Object value = expression.getValue(context);
System.out.println(value);
}
use of org.springframework.core.env.Environment in project spring-boot by spring-projects.
the class OnEndpointElementCondition method getEndpointOutcome.
protected ConditionOutcome getEndpointOutcome(ConditionContext context, String endpointName) {
Environment environment = context.getEnvironment();
String enabledProperty = this.prefix + endpointName + ".enabled";
if (environment.containsProperty(enabledProperty)) {
boolean match = environment.getProperty(enabledProperty, Boolean.class, true);
return new ConditionOutcome(match, ConditionMessage.forCondition(this.annotationType).because(this.prefix + endpointName + ".enabled is " + match));
}
return null;
}
use of org.springframework.core.env.Environment in project spring-boot by spring-projects.
the class CacheCondition method getMatchOutcome.
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
String sourceClass = "";
if (metadata instanceof ClassMetadata) {
sourceClass = ((ClassMetadata) metadata).getClassName();
}
ConditionMessage.Builder message = ConditionMessage.forCondition("Cache", sourceClass);
Environment environment = context.getEnvironment();
try {
BindResult<CacheType> specified = Binder.get(environment).bind("spring.cache.type", CacheType.class);
if (!specified.isBound()) {
return ConditionOutcome.match(message.because("automatic cache type"));
}
CacheType required = CacheConfigurations.getType(((AnnotationMetadata) metadata).getClassName());
if (specified.get() == required) {
return ConditionOutcome.match(message.because(specified.get() + " cache type"));
}
} catch (BindException ex) {
}
return ConditionOutcome.noMatch(message.because("unknown cache type"));
}
use of org.springframework.core.env.Environment in project spring-boot by spring-projects.
the class ConfigurationPropertySourcesTests method fromPropertySourceShouldFlattenPropertySources.
@Test
void fromPropertySourceShouldFlattenPropertySources() {
StandardEnvironment environment = new StandardEnvironment();
environment.getPropertySources().addFirst(new MapPropertySource("foo", Collections.singletonMap("foo", "bar")));
environment.getPropertySources().addFirst(new MapPropertySource("far", Collections.singletonMap("far", "far")));
MutablePropertySources sources = new MutablePropertySources();
sources.addFirst(new PropertySource<Environment>("env", environment) {
@Override
public String getProperty(String key) {
return this.source.getProperty(key);
}
});
sources.addLast(new MapPropertySource("baz", Collections.singletonMap("baz", "barf")));
Iterable<ConfigurationPropertySource> configurationSources = ConfigurationPropertySources.from(sources);
assertThat(configurationSources.iterator()).toIterable().hasSize(5);
}
Aggregations