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


Java BeanFactoryResolver类代码示例

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


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

示例1: getKeyFilter

import org.springframework.context.expression.BeanFactoryResolver; //导入依赖的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.context.expression.BeanFactoryResolver; //导入依赖的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: createEvaluationContext

import org.springframework.context.expression.BeanFactoryResolver; //导入依赖的package包/类
/**
 * Create an {@link EvaluationContext}.
 * @param caches the current caches
 * @param method the method
 * @param args the method arguments
 * @param target the target object
 * @param targetClass the target class
 * @param result the return value (can be {@code null}) or
 * {@link #NO_RESULT} if there is no return at this time
 * @return the evaluation context
 */
public EvaluationContext createEvaluationContext(Collection<? extends Cache> caches,
		Method method, Object[] args, Object target, Class<?> targetClass, Object result,
		BeanFactory beanFactory) {

	CacheExpressionRootObject rootObject = new CacheExpressionRootObject(
			caches, method, args, target, targetClass);
	Method targetMethod = getTargetMethod(targetClass, method);
	CacheEvaluationContext evaluationContext = new CacheEvaluationContext(
			rootObject, targetMethod, args, getParameterNameDiscoverer());
	if (result == RESULT_UNAVAILABLE) {
		evaluationContext.addUnavailableVariable(RESULT_VARIABLE);
	}
	else if (result != NO_RESULT) {
		evaluationContext.setVariable(RESULT_VARIABLE, result);
	}
	if (beanFactory != null) {
		evaluationContext.setBeanResolver(new BeanFactoryResolver(beanFactory));
	}
	return evaluationContext;
}
 
开发者ID:txazo,项目名称:spring,代码行数:32,代码来源:CacheOperationExpressionEvaluator.java

示例4: conversionService

import org.springframework.context.expression.BeanFactoryResolver; //导入依赖的package包/类
private ConversionService conversionService(ApplicationContext applicationContext) {
	// TODO should be also able to resolve a url to a bean/method
	BeanFactoryResolver beanResolver = new BeanFactoryResolver(applicationContext) {
		@Override
		public Object resolve(EvaluationContext context, String beanName)
				throws AccessException {
			return super.resolve(context,
					(beanName.startsWith("bean:") ? beanName.substring("bean:".length())
							: beanName));
		}
	};

	ConversionServiceFactoryBean factoryBean = new ConversionServiceFactoryBean();
	Set<Converter<?, ?>> cons = new HashSet<Converter<?, ?>>();

	cons.add(new DtoCheckConverter(beanResolver));
	cons.add(new DtoOperationConverter(beanResolver));
	factoryBean.setConverters(cons);
	factoryBean.afterPropertiesSet();

	return factoryBean.getObject();
}
 
开发者ID:cucina,项目名称:opencucina,代码行数:23,代码来源:ClientApplication.java

示例5: createEvaluationContext

import org.springframework.context.expression.BeanFactoryResolver; //导入依赖的package包/类
/**
 * 创建SpEL执行上下文
 *
 * @param rootObject
 *            SpEL表达式根对象
 * @param context
 *            Beetl上下文对象
 * @return SpEL表达式执行上下文
 */
private EvaluationContext createEvaluationContext(Object rootObject, Context beetlContext) {
	StandardEvaluationContext context = new StandardEvaluationContext(rootObject);

	// 允许使用#context访问Beetl上下文
	context.setVariable("context", beetlContext);
	// 允许使用#global访问Beetl上下文的全局变量
	context.setVariable("global", beetlContext.globalVar);
	// 注册WebRender定义的全局变量
	context.setVariable("ctxPath", beetlContext.getGlobal("ctxPath"));
	context.setVariable("servlet", beetlContext.getGlobal("servlet"));
	context.setVariable("parameter", beetlContext.getGlobal("parameter"));
	context.setVariable("request", beetlContext.getGlobal("request"));
	context.setVariable("session", beetlContext.getGlobal("session"));
	// 允许使用属性格式访问Map
	context.addPropertyAccessor(new MapAccessor());
	// 允许访问Spring容器Bean
	context.setBeanResolver(new BeanFactoryResolver(applicationContext));

	return context;
}
 
开发者ID:javamonkey,项目名称:beetl2.0,代码行数:30,代码来源:SpELFunction.java

示例6: executeCondition

import org.springframework.context.expression.BeanFactoryResolver; //导入依赖的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

示例7: setApplicationContext

import org.springframework.context.expression.BeanFactoryResolver; //导入依赖的package包/类
public SpringDataFetcher setApplicationContext(ApplicationContext context) {
	this.context = context;
	// setup the bean factory resolver
	beanFactoryResolver = new BeanFactoryResolver(context);

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

示例8: createEvaluationContext

import org.springframework.context.expression.BeanFactoryResolver; //导入依赖的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

示例9: createEvaluationContext

import org.springframework.context.expression.BeanFactoryResolver; //导入依赖的package包/类
/**
 * Create the suitable {@link EvaluationContext} for the specified event handling
 * on the specified method.
 */
public EvaluationContext createEvaluationContext(ApplicationEvent event, Class<?> targetClass,
		Method method, Object[] args, BeanFactory beanFactory) {

	Method targetMethod = getTargetMethod(targetClass, method);
	EventExpressionRootObject root = new EventExpressionRootObject(event, args);
	MethodBasedEvaluationContext evaluationContext = new MethodBasedEvaluationContext(
			root, targetMethod, args, getParameterNameDiscoverer());
	if (beanFactory != null) {
		evaluationContext.setBeanResolver(new BeanFactoryResolver(beanFactory));
	}
	return evaluationContext;
}
 
开发者ID:txazo,项目名称:spring,代码行数:17,代码来源:EventExpressionEvaluator.java

示例10: getBrokerCount

import org.springframework.context.expression.BeanFactoryResolver; //导入依赖的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

示例11: createEvaluationContext

import org.springframework.context.expression.BeanFactoryResolver; //导入依赖的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

示例12: afterPropertiesSet

import org.springframework.context.expression.BeanFactoryResolver; //导入依赖的package包/类
/**
 * JAVADOC Method Level Comments
 *
 * @throws Exception JAVADOC.
 */
@Override
public void afterPropertiesSet()
    throws Exception {
    if (!resolvers.containsKey("bean")) {
        resolvers.put("bean", new BeanFactoryResolver(beanFactory));
    }

    if (!resolvers.containsKey("class")) {
        resolvers.put("class", new ClassResolver());
    }
}
 
开发者ID:cucina,项目名称:opencucina,代码行数:17,代码来源:ProtocolResolver.java

示例13: setApplicationContext

import org.springframework.context.expression.BeanFactoryResolver; //导入依赖的package包/类
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {

	context.addPropertyAccessor(new BeanFactoryAccessor());
	context.setBeanResolver(new BeanFactoryResolver(applicationContext));
	context.setRootObject(applicationContext);
}
 
开发者ID:yiduwangkai,项目名称:dubbox-solr,代码行数:8,代码来源:SimpleSolrPersistentEntity.java

示例14: setApplicationContext

import org.springframework.context.expression.BeanFactoryResolver; //导入依赖的package包/类
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    context.addPropertyAccessor(new BeanFactoryAccessor());
    context.setBeanResolver(new BeanFactoryResolver(applicationContext));
    context.setRootObject(applicationContext);
}
 
开发者ID:Microsoft,项目名称:spring-data-documentdb,代码行数:6,代码来源:BasicDocumentDbPersistentEntity.java

示例15: setApplicationContext

import org.springframework.context.expression.BeanFactoryResolver; //导入依赖的package包/类
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    context.addPropertyAccessor(new BeanFactoryAccessor());
    context.setBeanResolver(new BeanFactoryResolver(applicationContext));
    context.setRootObject(applicationContext);
}
 
开发者ID:SeniorAdvisor,项目名称:spring-data-cloudant,代码行数:7,代码来源:BasicCloudantPersistentEntity.java


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