@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"));
}
java类org.springframework.beans.factory.config.BeanExpressionResolver的实例源码
DefaultListableBeanFactoryTests.java 文件源码
项目:spring4-understanding
阅读 27
收藏 0
点赞 0
评论 0
AutoPropertiesFactoryBean.java 文件源码
项目:spring-autoproperties
阅读 22
收藏 0
点赞 0
评论 0
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()));
}
ApplicationMetricsProperties.java 文件源码
项目:spring-cloud-stream
阅读 27
收藏 0
点赞 0
评论 0
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;
}
QueueMessageHandler.java 文件源码
项目:spring-cloud-aws
阅读 57
收藏 0
点赞 0
评论 0
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);
}
}
AbstractNamedValueMethodArgumentResolver.java 文件源码
项目:lams
阅读 39
收藏 0
点赞 0
评论 0
/**
* 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);
}
WxContextUtils.java 文件源码
项目:FastBootWeixin
阅读 21
收藏 0
点赞 0
评论 0
/**
* 解析参数值并执行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();
}
AbstractNamedValueMethodArgumentResolver.java 文件源码
项目:spring4-understanding
阅读 38
收藏 0
点赞 0
评论 0
/**
* 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);
}
AnnotationMethodHandlerAdapter.java 文件源码
项目:spring4-understanding
阅读 18
收藏 0
点赞 0
评论 0
@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);
}
AnnotationMethodHandlerAdapter.java 文件源码
项目:spring4-understanding
阅读 28
收藏 0
点赞 0
评论 0
@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);
}
AbstractNamedValueMethodArgumentResolver.java 文件源码
项目:spring4-understanding
阅读 22
收藏 0
点赞 0
评论 0
/**
* 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);
}
AnnotationMethodHandlerAdapter.java 文件源码
项目:class-guard
阅读 23
收藏 0
点赞 0
评论 0
@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);
}
AnnotationMethodHandlerAdapter.java 文件源码
项目:class-guard
阅读 28
收藏 0
点赞 0
评论 0
@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);
}
AbstractNamedValueMethodArgumentResolver.java 文件源码
项目:class-guard
阅读 33
收藏 0
点赞 0
评论 0
/**
* 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);
}
ExtendableAnnotationMethodHandlerAdapter.java 文件源码
项目:jresplus
阅读 18
收藏 0
点赞 0
评论 0
@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);
}
SendToHandlerMethodReturnValueHandler.java 文件源码
项目:spring-cloud-aws
阅读 21
收藏 0
点赞 0
评论 0
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;
}
AbstractBeanFactory.java 文件源码
项目:lams
阅读 22
收藏 0
点赞 0
评论 0
@Override
public void setBeanExpressionResolver(BeanExpressionResolver resolver) {
this.beanExpressionResolver = resolver;
}
AbstractBeanFactory.java 文件源码
项目:lams
阅读 26
收藏 0
点赞 0
评论 0
@Override
public BeanExpressionResolver getBeanExpressionResolver() {
return this.beanExpressionResolver;
}
AbstractBeanFactory.java 文件源码
项目:spring4-understanding
阅读 26
收藏 0
点赞 0
评论 0
@Override
public void setBeanExpressionResolver(BeanExpressionResolver resolver) {
this.beanExpressionResolver = resolver;
}
AbstractBeanFactory.java 文件源码
项目:spring4-understanding
阅读 22
收藏 0
点赞 0
评论 0
@Override
public BeanExpressionResolver getBeanExpressionResolver() {
return this.beanExpressionResolver;
}
AbstractBeanFactory.java 文件源码
项目:spring
阅读 21
收藏 0
点赞 0
评论 0
@Override
public void setBeanExpressionResolver(BeanExpressionResolver resolver) {
this.beanExpressionResolver = resolver;
}
AbstractBeanFactory.java 文件源码
项目:spring
阅读 20
收藏 0
点赞 0
评论 0
@Override
public BeanExpressionResolver getBeanExpressionResolver() {
return this.beanExpressionResolver;
}
AbstractBeanFactory.java 文件源码
项目:class-guard
阅读 21
收藏 0
点赞 0
评论 0
public void setBeanExpressionResolver(BeanExpressionResolver resolver) {
this.beanExpressionResolver = resolver;
}
AbstractBeanFactory.java 文件源码
项目:class-guard
阅读 27
收藏 0
点赞 0
评论 0
public BeanExpressionResolver getBeanExpressionResolver() {
return this.beanExpressionResolver;
}