本文整理汇总了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";
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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());
}
}
示例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);
}
示例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);
}
示例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);
}