Search in sources :

Example 11 with BeanExpressionResolver

use of org.springframework.beans.factory.config.BeanExpressionResolver in project spring-framework by spring-projects.

the class DefaultListableBeanFactoryTests method expressionInStringArray.

@Test
void expressionInStringArray() {
    BeanExpressionResolver beanExpressionResolver = mock(BeanExpressionResolver.class);
    given(beanExpressionResolver.evaluate(eq("#{foo}"), any(BeanExpressionContext.class))).willReturn("classpath:/org/springframework/beans/factory/xml/util.properties");
    lbf.setBeanExpressionResolver(beanExpressionResolver);
    RootBeanDefinition rbd = new RootBeanDefinition(PropertiesFactoryBean.class);
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.add("locations", new String[] { "#{foo}" });
    rbd.setPropertyValues(pvs);
    lbf.registerBeanDefinition("myProperties", rbd);
    Properties properties = (Properties) lbf.getBean("myProperties");
    assertThat(properties.getProperty("foo")).isEqualTo("bar");
}
Also used : BeanExpressionResolver(org.springframework.beans.factory.config.BeanExpressionResolver) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Properties(java.util.Properties) BeanExpressionContext(org.springframework.beans.factory.config.BeanExpressionContext) Test(org.junit.jupiter.api.Test)

Example 12 with BeanExpressionResolver

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);
}
Also used : BeanExpressionResolver(org.springframework.beans.factory.config.BeanExpressionResolver) Nullable(org.springframework.lang.Nullable)

Example 13 with BeanExpressionResolver

use of org.springframework.beans.factory.config.BeanExpressionResolver in project spring-framework by spring-projects.

the class AbstractNamedValueArgumentResolver 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);
}
Also used : BeanExpressionResolver(org.springframework.beans.factory.config.BeanExpressionResolver) Nullable(org.springframework.lang.Nullable)

Aggregations

BeanExpressionResolver (org.springframework.beans.factory.config.BeanExpressionResolver)13 BeanExpressionContext (org.springframework.beans.factory.config.BeanExpressionContext)6 Nullable (org.springframework.lang.Nullable)4 Properties (java.util.Properties)2 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)2 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)2 StandardBeanExpressionResolver (org.springframework.context.expression.StandardBeanExpressionResolver)2 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1 ConfigurableBeanFactory (org.springframework.beans.factory.config.ConfigurableBeanFactory)1 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)1 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)1 ApplicationContext (org.springframework.context.ApplicationContext)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)1