当前位置: 首页>>代码示例>>Java>>正文


Java BeanExpressionResolver类代码示例

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


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

示例1: testExpressionInStringArray

import org.springframework.beans.factory.config.BeanExpressionResolver; //导入依赖的package包/类
@Test
public void testExpressionInStringArray() {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	BeanExpressionResolver beanExpressionResolver = mock(BeanExpressionResolver.class);
	when(beanExpressionResolver.evaluate(eq("#{foo}"), Matchers.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"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:DefaultListableBeanFactoryTests.java

示例2: resolveValue

import org.springframework.beans.factory.config.BeanExpressionResolver; //导入依赖的package包/类
private Object resolveValue(Method method) {
    Value val = AnnotationUtils.findAnnotation(method, Value.class);
    if (val != null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug(String.format("Resolving @Value annotation on %s with key %s",
                    method.getName(), val.value()));
        }
        ConfigurableBeanFactory beanFactory = (ConfigurableBeanFactory) getBeanFactory();
        String strValue = beanFactory.resolveEmbeddedValue(val.value());
        BeanExpressionResolver resolver = beanFactory.getBeanExpressionResolver();

        Object unconvertedResult = resolver.evaluate(strValue, new BeanExpressionContext(beanFactory, null));
        TypeConverter converter = beanFactory.getTypeConverter();
        return converter.convertIfNecessary(unconvertedResult, method.getReturnType());
    }
    String message = "Method %s on interface %s must be annotated with @Value for auto-properties to work!";
    throw new AutoPropertiesException(String.format(message, method.getName(), method.getDeclaringClass().getName()));
}
 
开发者ID:mdaniline,项目名称:spring-autoproperties,代码行数:19,代码来源:AutoPropertiesFactoryBean.java

示例3: buildExportProperties

import org.springframework.beans.factory.config.BeanExpressionResolver; //导入依赖的package包/类
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;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:27,代码来源:ApplicationMetricsProperties.java

示例4: resolveName

import org.springframework.beans.factory.config.BeanExpressionResolver; //导入依赖的package包/类
private String[] resolveName(String name) {
    if (!(getApplicationContext() instanceof ConfigurableApplicationContext)) {
        return wrapInStringArray(name);
    }

    ConfigurableApplicationContext applicationContext = (ConfigurableApplicationContext) getApplicationContext();
    ConfigurableBeanFactory configurableBeanFactory = applicationContext.getBeanFactory();

    String placeholdersResolved = configurableBeanFactory.resolveEmbeddedValue(name);
    BeanExpressionResolver exprResolver = configurableBeanFactory.getBeanExpressionResolver();
    if (exprResolver == null) {
        return wrapInStringArray(name);
    }
    Object result = exprResolver.evaluate(placeholdersResolved, new BeanExpressionContext(configurableBeanFactory, null));
    if (result instanceof String[]) {
        return (String[]) result;
    } else if (result != null) {
        return wrapInStringArray(result);
    } else {
        return wrapInStringArray(name);
    }
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:23,代码来源:QueueMessageHandler.java

示例5: resolveDefaultValue

import org.springframework.beans.factory.config.BeanExpressionResolver; //导入依赖的package包/类
/**
 * Resolves the given default value into an argument value.
 */
private Object resolveDefaultValue(String defaultValue) {
	if (this.configurableBeanFactory == null) {
		return defaultValue;
	}
	String placeholdersResolved = this.configurableBeanFactory.resolveEmbeddedValue(defaultValue);
	BeanExpressionResolver exprResolver = this.configurableBeanFactory.getBeanExpressionResolver();
	if (exprResolver == null) {
		return defaultValue;
	}
	return exprResolver.evaluate(placeholdersResolved, this.expressionContext);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:AbstractNamedValueMethodArgumentResolver.java

示例6: resolveStringValue

import org.springframework.beans.factory.config.BeanExpressionResolver; //导入依赖的package包/类
/**
 * 解析参数值并执行spel表达式,得到最终结果
 * Spring的@Value也是这样做的
 */
public static String resolveStringValue(String value) {
    String placeholdersResolved = configurableBeanFactory.resolveEmbeddedValue(value);
    BeanExpressionResolver exprResolver = configurableBeanFactory.getBeanExpressionResolver();
    if (exprResolver == null) {
        return value;
    }
    return exprResolver.evaluate(placeholdersResolved, expressionContext).toString();
}
 
开发者ID:FastBootWeixin,项目名称:FastBootWeixin,代码行数:13,代码来源:WxContextUtils.java

示例7: resolveDefaultValue

import org.springframework.beans.factory.config.BeanExpressionResolver; //导入依赖的package包/类
@Override
protected Object resolveDefaultValue(String value) {
	if (beanFactory == null) {
		return value;
	}
	String placeholdersResolved = beanFactory.resolveEmbeddedValue(value);
	BeanExpressionResolver exprResolver = beanFactory.getBeanExpressionResolver();
	if (exprResolver == null) {
		return value;
	}
	return exprResolver.evaluate(placeholdersResolved, expressionContext);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:AnnotationMethodHandlerAdapter.java

示例8: resolveDefaultValue

import org.springframework.beans.factory.config.BeanExpressionResolver; //导入依赖的package包/类
@Override
protected Object resolveDefaultValue(String value) {
	if (beanFactory == null) {
		return value;
	}
	String placeholdersResolved = beanFactory
			.resolveEmbeddedValue(value);
	BeanExpressionResolver exprResolver = beanFactory
			.getBeanExpressionResolver();
	if (exprResolver == null) {
		return value;
	}
	return exprResolver.evaluate(placeholdersResolved,
			expressionContext);
}
 
开发者ID:xiyelife,项目名称:jresplus,代码行数:16,代码来源:ExtendableAnnotationMethodHandlerAdapter.java

示例9: resolveName

import org.springframework.beans.factory.config.BeanExpressionResolver; //导入依赖的package包/类
private String resolveName(String name) {
    if (!(this.beanFactory instanceof ConfigurableBeanFactory)) {
        return name;
    }

    ConfigurableBeanFactory configurableBeanFactory = (ConfigurableBeanFactory) this.beanFactory;

    String placeholdersResolved = configurableBeanFactory.resolveEmbeddedValue(name);
    BeanExpressionResolver exprResolver = configurableBeanFactory.getBeanExpressionResolver();
    if (exprResolver == null) {
        return name;
    }
    Object result = exprResolver.evaluate(placeholdersResolved, new BeanExpressionContext(configurableBeanFactory, null));
    return result != null ? result.toString() : name;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:16,代码来源:SendToHandlerMethodReturnValueHandler.java

示例10: setBeanExpressionResolver

import org.springframework.beans.factory.config.BeanExpressionResolver; //导入依赖的package包/类
@Override
public void setBeanExpressionResolver(BeanExpressionResolver resolver) {
	this.beanExpressionResolver = resolver;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:5,代码来源:AbstractBeanFactory.java

示例11: getBeanExpressionResolver

import org.springframework.beans.factory.config.BeanExpressionResolver; //导入依赖的package包/类
@Override
public BeanExpressionResolver getBeanExpressionResolver() {
	return this.beanExpressionResolver;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:5,代码来源:AbstractBeanFactory.java

示例12: setBeanExpressionResolver

import org.springframework.beans.factory.config.BeanExpressionResolver; //导入依赖的package包/类
public void setBeanExpressionResolver(BeanExpressionResolver resolver) {
	this.beanExpressionResolver = resolver;
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:4,代码来源:AbstractBeanFactory.java

示例13: getBeanExpressionResolver

import org.springframework.beans.factory.config.BeanExpressionResolver; //导入依赖的package包/类
public BeanExpressionResolver getBeanExpressionResolver() {
	return this.beanExpressionResolver;
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:4,代码来源:AbstractBeanFactory.java


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