Java Code Examples for org.springframework.beans.factory.config.ConfigurableBeanFactory#getBeanExpressionResolver()

The following examples show how to use org.springframework.beans.factory.config.ConfigurableBeanFactory#getBeanExpressionResolver() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ValueResolver.java    From rqueue with Apache License 2.0 6 votes vote down vote up
@NonNull
private static Object resolveExpression(ApplicationContext applicationContext, String name) {
  if (applicationContext instanceof ConfigurableApplicationContext) {
    ConfigurableBeanFactory configurableBeanFactory =
        ((ConfigurableApplicationContext) applicationContext).getBeanFactory();
    String placeholdersResolved = configurableBeanFactory.resolveEmbeddedValue(name);
    BeanExpressionResolver exprResolver = configurableBeanFactory.getBeanExpressionResolver();
    if (exprResolver == null) {
      return name;
    }
    Object result =
        exprResolver.evaluate(
            placeholdersResolved, new BeanExpressionContext(configurableBeanFactory, null));
    if (result != null) {
      return result;
    }
  }
  return name;
}
 
Example 2
Source File: SendToHandlerMethodReturnValueHandler.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 3
Source File: PlaceholderHelper.java    From apollo with Apache License 2.0 5 votes vote down vote up
private Object evaluateBeanDefinitionString(ConfigurableBeanFactory beanFactory, String value,
    BeanDefinition beanDefinition) {
  if (beanFactory.getBeanExpressionResolver() == null) {
    return value;
  }
  Scope scope = (beanDefinition != null ? beanFactory
      .getRegisteredScope(beanDefinition.getScope()) : null);
  return beanFactory.getBeanExpressionResolver()
      .evaluate(value, new BeanExpressionContext(beanFactory, scope));
}
 
Example 4
Source File: QueueMessageHandler.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
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);
	}
}