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


Java StandardEvaluationContext.setBeanResolver方法代码示例

本文整理汇总了Java中org.springframework.expression.spel.support.StandardEvaluationContext.setBeanResolver方法的典型用法代码示例。如果您正苦于以下问题:Java StandardEvaluationContext.setBeanResolver方法的具体用法?Java StandardEvaluationContext.setBeanResolver怎么用?Java StandardEvaluationContext.setBeanResolver使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.expression.spel.support.StandardEvaluationContext的用法示例。


在下文中一共展示了StandardEvaluationContext.setBeanResolver方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getKeyFilter

import org.springframework.expression.spel.support.StandardEvaluationContext; //导入方法依赖的package包/类
/**
 * Creates the key filter lambda which is responsible to decide how the rate limit will be performed. The key
 * is the unique identifier like an IP address or a username.
 * 
 * @param url is used to generated a unique cache key
 * @param rateLimit the {@link RateLimit} configuration which holds the skip condition string
 * @param expressionParser is used to evaluate the expression if the filter key type is EXPRESSION.
 * @param beanFactory used to get full access to all java beans in the SpEl
 * @return should not been null. If no filter key type is matching a plain 1 is returned so that all requests uses the same key.
 */
public KeyFilter getKeyFilter(String url, RateLimit rateLimit, ExpressionParser expressionParser, BeanFactory beanFactory) {
	
	switch(rateLimit.getFilterKeyType()) {
	case IP:
		return (request) -> url + "-" + request.getRemoteAddr();
	case EXPRESSION:
		String expression = rateLimit.getExpression();
		if(StringUtils.isEmpty(expression)) {
			throw new MissingKeyFilterExpressionException();
		}
		StandardEvaluationContext context = new StandardEvaluationContext();
		context.setBeanResolver(new BeanFactoryResolver(beanFactory));
		return  (request) -> {
			//TODO performance problem - how can the request object reused in the expression without setting it as a rootObject
			Expression expr = expressionParser.parseExpression(rateLimit.getExpression()); 
			final String value = expr.getValue(context, request, String.class);
			return url + "-" + value;
		};
	
	}
	return (request) -> url + "-" + "1";
}
 
开发者ID:MarcGiffing,项目名称:bucket4j-spring-boot-starter,代码行数:33,代码来源:Bucket4JBaseConfiguration.java

示例2: skipCondition

import org.springframework.expression.spel.support.StandardEvaluationContext; //导入方法依赖的package包/类
/**
 * Creates the lambda for the skip condition which will be evaluated on each request
 * 
 * @param rateLimit the {@link RateLimit} configuration which holds the skip condition string
 * @param expressionParser is used to evaluate the skip expression
 * @param beanFactory used to get full access to all java beans in the SpEl
 * @return the lamdba condition which will be evaluated lazy - null if there is no condition available.
 */
public Condition skipCondition(RateLimit rateLimit, ExpressionParser expressionParser, BeanFactory beanFactory) {
	StandardEvaluationContext context = new StandardEvaluationContext();
	context.setBeanResolver(new BeanFactoryResolver(beanFactory));
	
	if(rateLimit.getSkipCondition() != null) {
		return  (request) -> {
			Expression expr = expressionParser.parseExpression(rateLimit.getSkipCondition()); 
			Boolean value = expr.getValue(context, request, Boolean.class);
			return value;
		};
	}
	return null;
}
 
开发者ID:MarcGiffing,项目名称:bucket4j-spring-boot-starter,代码行数:22,代码来源:Bucket4JBaseConfiguration.java

示例3: SPR11445_beanReference

import org.springframework.expression.spel.support.StandardEvaluationContext; //导入方法依赖的package包/类
@Test
public void SPR11445_beanReference() {
	StandardEvaluationContext context = new StandardEvaluationContext();
	context.setBeanResolver(new Spr11445Class());
	Expression expr = new SpelExpressionParser().parseRaw("@bean.echo(@bean.parameter())");
	assertEquals(1, expr.getValue(context));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:8,代码来源:SpelReproTests.java

示例4: executeCondition

import org.springframework.expression.spel.support.StandardEvaluationContext; //导入方法依赖的package包/类
/**
 * Creates the lambda for the execute condition which will be evaluated on each request.
 * 
 * @param rateLimit the {@link RateLimit} configuration which holds the execute condition string
 * @param expressionParser is used to evaluate the execution expression
 * @param beanFactory used to get full access to all java beans in the SpEl
 * @return the lamdba condition which will be evaluated lazy - null if there is no condition available.
 */
public Condition executeCondition(RateLimit rateLimit, ExpressionParser expressionParser, BeanFactory beanFactory) {
	StandardEvaluationContext context = new StandardEvaluationContext();
	context.setBeanResolver(new BeanFactoryResolver(beanFactory));
	
	if(rateLimit.getExecuteCondition() != null) {
		return (request) -> {
			Expression expr = expressionParser.parseExpression(rateLimit.getExecuteCondition()); 
			Boolean value = expr.getValue(context, request, Boolean.class);
			return value;
		};
	}
	return null;
}
 
开发者ID:MarcGiffing,项目名称:bucket4j-spring-boot-starter,代码行数:22,代码来源:Bucket4JBaseConfiguration.java

示例5: getEvaluationContext

import org.springframework.expression.spel.support.StandardEvaluationContext; //导入方法依赖的package包/类
private EvaluationContext getEvaluationContext(Object rootObject, Object[] arguments) {
	StandardEvaluationContext standardEvaluationContext = new StandardEvaluationContext();
	standardEvaluationContext.setBeanResolver(beanFactoryResolver);

	// add the parameter values as variables
	int index = 0;
	for (String name : argumentTypeMap.keySet()) {
		standardEvaluationContext.setVariable(name, arguments[index++]);
	}
	standardEvaluationContext.setRootObject(rootObject);

	return standardEvaluationContext;
}
 
开发者ID:bpatters,项目名称:schemagen-graphql,代码行数:14,代码来源:SpringDataFetcher.java

示例6: createEvaluationContext

import org.springframework.expression.spel.support.StandardEvaluationContext; //导入方法依赖的package包/类
private EvaluationContext createEvaluationContext(PageContext pageContext) {
	StandardEvaluationContext context = new StandardEvaluationContext();
	context.addPropertyAccessor(new JspPropertyAccessor(pageContext));
	context.addPropertyAccessor(new MapAccessor());
	context.addPropertyAccessor(new EnvironmentAccessor());
	context.setBeanResolver(new BeanFactoryResolver(getRequestContext().getWebApplicationContext()));
	ConversionService conversionService = getConversionService(pageContext);
	if (conversionService != null) {
		context.setTypeConverter(new StandardTypeConverter(conversionService));
	}
	return context;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:EvalTag.java

示例7: getBrokerCount

import org.springframework.expression.spel.support.StandardEvaluationContext; //导入方法依赖的package包/类
private int getBrokerCount() {
    LocalEntityManagerFactoryBean entityManagerFactory = applicationContext.getBean("&entityManagerFactory", LocalEntityManagerFactoryBean.class);

    //uses Spring EL so we don't need to reference the classes
    StandardEvaluationContext context = new StandardEvaluationContext(entityManagerFactory);
    context.setBeanResolver(new BeanFactoryResolver(applicationContext));
    SpelExpressionParser parser = new SpelExpressionParser();
    Expression expression = parser.parseExpression("nativeEntityManagerFactory.brokerFactory.openBrokers"); 
    List<?> brokers = expression.getValue(context, List.class);

    return brokers.size();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:13,代码来源:JpaRouteSharedEntityManagerTest.java

示例8: createEvaluationContext

import org.springframework.expression.spel.support.StandardEvaluationContext; //导入方法依赖的package包/类
private EvaluationContext createEvaluationContext(Exchange exchange) {
    StandardEvaluationContext evaluationContext = new StandardEvaluationContext(new RootObject(exchange));
    if (exchange.getContext() instanceof SpringCamelContext) {
        // Support references (like @foo) in expressions to beans defined in the Registry/ApplicationContext
        ApplicationContext applicationContext = ((SpringCamelContext) exchange.getContext()).getApplicationContext();
        evaluationContext.setBeanResolver(new BeanFactoryResolver(applicationContext));
    }
    return evaluationContext;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:10,代码来源:SpelExpression.java


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