INT-1727 removed the runtime resolution of bean in DefaultScriptVariableSource if the actual instance is RuntimeBeanReference

This commit is contained in:
Oleg Zhurakousky
2011-01-28 10:08:07 -05:00
parent bda613709f
commit 2df24cc603
4 changed files with 12 additions and 18 deletions

View File

@@ -22,7 +22,6 @@ import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.integration.Message;
import org.springframework.util.CollectionUtils;
@@ -59,13 +58,7 @@ public class DefaultScriptVariableSource implements BeanFactoryAware, ScriptVari
if (!CollectionUtils.isEmpty(variableMap)){
for (String variableName : variableMap.keySet()) {
Object variableValue = variableMap.get(variableName);
if (variableValue instanceof RuntimeBeanReference){
String beanName = ((RuntimeBeanReference)variableValue).getBeanName();
scriptVariables.put(variableName, this.beanFactory.getBean(beanName));
}
else {
scriptVariables.put(variableName, variableValue);
}
scriptVariables.put(variableName, variableValue);
}
}
// custom logic

View File

@@ -16,15 +16,14 @@
package org.springframework.integration.groovy.config;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.w3c.dom.Element;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.beans.factory.support.ManagedMap;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.beans.factory.xml.XmlReaderContext;
@@ -85,7 +84,7 @@ public class GroovyScriptParser extends AbstractSingleBeanDefinitionParser {
BeanDefinitionBuilder scriptVariableSourceBuilder =
BeanDefinitionBuilder.genericBeanDefinition("org.springframework.integration.groovy.DefaultScriptVariableSource");
Map<String, Object> variableMap = new HashMap<String, Object>();
ManagedMap<String, Object> variableMap = new ManagedMap<String, Object>();
for (Element childElement : variableElements) {
String variableName = childElement.getAttribute("name");
String variableValue = childElement.getAttribute("value");

View File

@@ -3,12 +3,11 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:groovy="http://www.springframework.org/schema/integration/groovy"
xsi:schemaLocation="http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/groovy
http://www.springframework.org/schema/integration/groovy/spring-integration-groovy-2.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/groovy http://www.springframework.org/schema/integration/groovy/spring-integration-groovy-2.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<service-activator input-channel="referencedScriptInput">
<groovy:script location="org/springframework/integration/groovy/config/GroovyServiceActivatorTests.groovy">
@@ -35,6 +34,8 @@
</groovy:script>
</service-activator>
<beans:bean id="date" class="java.util.Date" scope="prototype"/>
<beans:bean id="date" class="java.util.Date" scope="prototype">
<aop:scoped-proxy/>
</beans:bean>
</beans:beans>

View File

@@ -68,6 +68,7 @@ public class GroovyServiceActivatorTests {
String value1 = (String) replyChannel.receive(0).getPayload();
String value2 = (String) replyChannel.receive(0).getPayload();
String value3 = (String) replyChannel.receive(0).getPayload();
System.out.println(value1 + "\n" + value2 + "\n" + value3);
assertTrue(value1.startsWith("groovy-test-1-foo - bar"));
assertTrue(value2.startsWith("groovy-test-2-foo - bar"));
assertTrue(value3.startsWith("groovy-test-3-foo - bar"));