use of org.springframework.beans.factory.config.BeanExpressionResolver in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testExpressionInStringArray.
@Test
public void testExpressionInStringArray() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
BeanExpressionResolver beanExpressionResolver = mock(BeanExpressionResolver.class);
when(beanExpressionResolver.evaluate(eq("#{foo}"), ArgumentMatchers.any(BeanExpressionContext.class))).thenReturn("classpath:/org/springframework/beans/factory/xml/util.properties");
bf.setBeanExpressionResolver(beanExpressionResolver);
RootBeanDefinition rbd = new RootBeanDefinition(PropertiesFactoryBean.class);
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("locations", new String[] { "#{foo}" });
rbd.setPropertyValues(pvs);
bf.registerBeanDefinition("myProperties", rbd);
Properties properties = (Properties) bf.getBean("myProperties");
assertEquals("bar", properties.getProperty("foo"));
}
use of org.springframework.beans.factory.config.BeanExpressionResolver in project spring-cloud-stream by spring-cloud.
the class ApplicationMetricsProperties method buildExportProperties.
private Map<String, Object> buildExportProperties() {
Map<String, Object> props = new HashMap<>();
if (!ObjectUtils.isEmpty(this.properties)) {
Map<String, String> target = bindProperties();
BeanExpressionResolver beanExpressionResolver = ((ConfigurableApplicationContext) applicationContext).getBeanFactory().getBeanExpressionResolver();
BeanExpressionContext expressionContext = new BeanExpressionContext(((ConfigurableApplicationContext) applicationContext).getBeanFactory(), null);
for (Entry<String, String> entry : target.entrySet()) {
if (isMatch(entry.getKey(), this.properties, null)) {
String stringValue = ObjectUtils.nullSafeToString(entry.getValue());
Object exportedValue = null;
if (stringValue != null) {
exportedValue = stringValue.startsWith("#{") ? beanExpressionResolver.evaluate(environment.resolvePlaceholders(stringValue), expressionContext) : environment.resolvePlaceholders(stringValue);
}
props.put(entry.getKey(), exportedValue);
}
}
}
return props;
}
use of org.springframework.beans.factory.config.BeanExpressionResolver in project spring-framework by spring-projects.
the class AbstractNamedValueMethodArgumentResolver method resolveEmbeddedValuesAndExpressions.
/**
* Resolve the given annotation-specified value,
* potentially containing placeholders and expressions.
*/
@Nullable
private Object resolveEmbeddedValuesAndExpressions(String value) {
if (this.configurableBeanFactory == null || this.expressionContext == null) {
return value;
}
String placeholdersResolved = this.configurableBeanFactory.resolveEmbeddedValue(value);
BeanExpressionResolver exprResolver = this.configurableBeanFactory.getBeanExpressionResolver();
if (exprResolver == null) {
return value;
}
return exprResolver.evaluate(placeholdersResolved, this.expressionContext);
}
use of org.springframework.beans.factory.config.BeanExpressionResolver in project spring-boot by spring-projects.
the class OnExpressionCondition method evaluateExpression.
private Boolean evaluateExpression(ConfigurableListableBeanFactory beanFactory, String expression) {
BeanExpressionResolver resolver = beanFactory.getBeanExpressionResolver();
if (resolver == null) {
resolver = new StandardBeanExpressionResolver();
}
BeanExpressionContext expressionContext = new BeanExpressionContext(beanFactory, null);
Object result = resolver.evaluate(expression, expressionContext);
return (result != null && (boolean) result);
}
use of org.springframework.beans.factory.config.BeanExpressionResolver in project spring-framework by spring-projects.
the class AbstractNamedValueMethodArgumentResolver method resolveEmbeddedValuesAndExpressions.
/**
* Resolve the given annotation-specified value,
* potentially containing placeholders and expressions.
*/
@Nullable
private Object resolveEmbeddedValuesAndExpressions(String value) {
if (this.configurableBeanFactory == null || this.expressionContext == null) {
return value;
}
String placeholdersResolved = this.configurableBeanFactory.resolveEmbeddedValue(value);
BeanExpressionResolver exprResolver = this.configurableBeanFactory.getBeanExpressionResolver();
if (exprResolver == null) {
return value;
}
return exprResolver.evaluate(placeholdersResolved, this.expressionContext);
}
Aggregations