INT-1284 added SimpleBeanResolver to replace multiple inline, anonymous implementations
This commit is contained in:
@@ -22,9 +22,6 @@ import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.context.expression.MapAccessor;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.expression.AccessException;
|
||||
import org.springframework.expression.BeanResolver;
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
import org.springframework.expression.EvaluationException;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.ExpressionParser;
|
||||
@@ -34,6 +31,7 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
import org.springframework.expression.spel.support.StandardTypeConverter;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.context.SimpleBeanResolver;
|
||||
import org.springframework.integration.handler.ExpressionEvaluatingMessageProcessor;
|
||||
import org.springframework.integration.transformer.MessageTransformationException;
|
||||
|
||||
@@ -79,11 +77,7 @@ public class ExpressionEvaluatingMessageListProcessor implements BeanFactoryAwar
|
||||
*/
|
||||
public void setBeanFactory(final BeanFactory beanFactory) {
|
||||
if (beanFactory != null) {
|
||||
this.getEvaluationContext().setBeanResolver(new BeanResolver() {
|
||||
public Object resolve(EvaluationContext context, String beanName) throws AccessException {
|
||||
return beanFactory.getBean(beanName);
|
||||
}
|
||||
});
|
||||
this.getEvaluationContext().setBeanResolver(new SimpleBeanResolver(beanFactory));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.context;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.expression.AccessException;
|
||||
import org.springframework.expression.BeanResolver;
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @since 2.0
|
||||
*/
|
||||
public class SimpleBeanResolver implements BeanResolver {
|
||||
|
||||
private final BeanFactory beanFactory;
|
||||
|
||||
|
||||
public SimpleBeanResolver(BeanFactory beanFactory) {
|
||||
Assert.notNull(beanFactory, "beanFactory must not be null");
|
||||
this.beanFactory = beanFactory;
|
||||
}
|
||||
|
||||
|
||||
public final Object resolve(EvaluationContext context, String beanName) throws AccessException {
|
||||
return this.beanFactory.getBean(beanName);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,13 +21,11 @@ import java.util.Map;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.expression.AccessException;
|
||||
import org.springframework.expression.BeanResolver;
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.ExpressionParser;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
import org.springframework.integration.context.SimpleBeanResolver;
|
||||
import org.springframework.integration.core.MessageBuilder;
|
||||
import org.springframework.scheduling.Trigger;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -85,11 +83,9 @@ public class ScheduledMessageProducer extends MessageProducerSupport {
|
||||
protected void onInit() {
|
||||
super.onInit();
|
||||
final BeanFactory beanFactory = this.getBeanFactory();
|
||||
this.context.setBeanResolver(new BeanResolver() {
|
||||
public Object resolve(EvaluationContext context, String beanName) throws AccessException {
|
||||
return beanFactory.getBean(beanName);
|
||||
}
|
||||
});
|
||||
if (beanFactory != null) {
|
||||
this.context.setBeanResolver(new SimpleBeanResolver(beanFactory));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -28,9 +28,7 @@ import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.ParameterNameDiscoverer;
|
||||
import org.springframework.expression.AccessException;
|
||||
import org.springframework.expression.BeanResolver;
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
@@ -39,6 +37,7 @@ import org.springframework.integration.MessagingException;
|
||||
import org.springframework.integration.annotation.Header;
|
||||
import org.springframework.integration.annotation.Headers;
|
||||
import org.springframework.integration.annotation.Payload;
|
||||
import org.springframework.integration.context.SimpleBeanResolver;
|
||||
import org.springframework.integration.core.MessageBuilder;
|
||||
import org.springframework.integration.mapping.InboundMessageMapper;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -141,11 +140,7 @@ public class ArgumentArrayMessageMapper implements InboundMessageMapper<Object[]
|
||||
|
||||
public void setBeanFactory(final BeanFactory beanFactory) {
|
||||
if (beanFactory != null) {
|
||||
this.beanResolver = new BeanResolver() {
|
||||
public Object resolve(EvaluationContext context, String beanName) throws AccessException {
|
||||
return beanFactory.getBean(beanName);
|
||||
}
|
||||
};
|
||||
this.beanResolver = new SimpleBeanResolver(beanFactory);
|
||||
this.staticEvaluationContext.setBeanResolver(beanResolver);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,15 +19,13 @@ package org.springframework.integration.handler;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.context.expression.MapAccessor;
|
||||
import org.springframework.expression.AccessException;
|
||||
import org.springframework.expression.BeanResolver;
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.ExpressionParser;
|
||||
import org.springframework.expression.ParseException;
|
||||
import org.springframework.expression.spel.SpelParserConfiguration;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.context.SimpleBeanResolver;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -73,11 +71,7 @@ public class ExpressionEvaluatingMessageProcessor extends AbstractMessageProcess
|
||||
*/
|
||||
public void setBeanFactory(final BeanFactory beanFactory) {
|
||||
if (beanFactory != null) {
|
||||
this.getEvaluationContext().setBeanResolver(new BeanResolver() {
|
||||
public Object resolve(EvaluationContext context, String beanName) throws AccessException {
|
||||
return beanFactory.getBean(beanName);
|
||||
}
|
||||
});
|
||||
this.getEvaluationContext().setBeanResolver(new SimpleBeanResolver(beanFactory));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user