diff --git a/src/main/java/org/springframework/integration/flow/Flow.java b/src/main/java/org/springframework/integration/flow/Flow.java index b06d351..f927384 100644 --- a/src/main/java/org/springframework/integration/flow/Flow.java +++ b/src/main/java/org/springframework/integration/flow/Flow.java @@ -12,7 +12,6 @@ import org.apache.commons.logging.LogFactory; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.InitializingBean; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.BeanDefinitionValidationException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; @@ -124,7 +123,6 @@ public class Flow implements InitializingBean, BeanNameAware, ChannelResolver, A Assert.notEmpty(configLocations, "configLocations cannot be empty"); - /* * create a child application context */ @@ -140,7 +138,7 @@ public class Flow implements InitializingBean, BeanNameAware, ChannelResolver, A this.flowContext.setConfigLocations(configLocations); this.flowContext.refresh(); - + // Deep debug // FlowUtils.displayBeansGraph(flowContext.getBeanFactory()); // @@ -245,26 +243,28 @@ public class Flow implements InitializingBean, BeanNameAware, ChannelResolver, A "flow configuration contains no port configurations"); /* - * Verify that no channels in the flow context are shared in the parent context + * Verify that no channels in the flow context are shared in the parent + * context */ List errors = new ArrayList(); - + List channelNames = Arrays.asList(this.flowContext.getBeanNamesForType(MessageChannel.class)); - - Set referencedMessageChannels = FlowUtils.getReferencedMessageChannels(this.flowContext.getBeanFactory()); - - for (String referencedMessageChannel: referencedMessageChannels) { + + Set referencedMessageChannels = FlowUtils.getReferencedMessageChannels(this.flowContext + .getBeanFactory()); + + for (String referencedMessageChannel : referencedMessageChannels) { if (!channelNames.contains(referencedMessageChannel)) { - errors.add("Flow references channel [" + referencedMessageChannel + "] defined in the parent context. " + - "This channel should be explicitly defined in the flow context"); + errors.add("Flow references channel [" + referencedMessageChannel + "] defined in the parent context. " + + "This channel should be explicitly defined in the flow context"); } } - - if (errors.size() > 0 ) { - throw new BeanDefinitionValidationException("\n"+StringUtils.arrayToDelimitedString(errors.toArray(),"\n")); + + if (errors.size() > 0) { + throw new BeanDefinitionValidationException("\n" + + StringUtils.arrayToDelimitedString(errors.toArray(), "\n")); } } - private void bridgeMessagingPorts() { /* @@ -288,4 +288,8 @@ public class Flow implements InitializingBean, BeanNameAware, ChannelResolver, A public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.applicationContext = applicationContext; } + + public ApplicationContext getFlowContext() { + return this.flowContext; + } } diff --git a/src/test/java/org/springframework/integration/flow/config/xml/BarFactory.java b/src/test/java/org/springframework/integration/flow/config/xml/BarFactory.java new file mode 100644 index 0000000..02ba228 --- /dev/null +++ b/src/test/java/org/springframework/integration/flow/config/xml/BarFactory.java @@ -0,0 +1,25 @@ +package org.springframework.integration.flow.config.xml; + +import org.springframework.beans.factory.FactoryBean; + +public class BarFactory implements FactoryBean { + + @Override + public Bar getObject() throws Exception { + // TODO Auto-generated method stub + return new Bar(); + } + + @Override + public Class getObjectType() { + // TODO Auto-generated method stub + return Bar.class; + } + + @Override + public boolean isSingleton() { + // TODO Auto-generated method stub + return true; + } + +} diff --git a/src/test/java/org/springframework/integration/flow/config/xml/FlowWithAutowireTest.java b/src/test/java/org/springframework/integration/flow/config/xml/FlowWithAutowireTest.java index 387aab0..9916ef0 100644 --- a/src/test/java/org/springframework/integration/flow/config/xml/FlowWithAutowireTest.java +++ b/src/test/java/org/springframework/integration/flow/config/xml/FlowWithAutowireTest.java @@ -1,15 +1,22 @@ package org.springframework.integration.flow.config.xml; +import static org.junit.Assert.assertNotNull; + import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.integration.flow.Flow; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:/FlowWithAutowireTest-context.xml") public class FlowWithAutowireTest { + @Autowired + Flow flow; @Test public void test() { - + Foo foo = flow.getFlowContext().getBean(Foo.class); + assertNotNull(foo.bar); } } diff --git a/src/test/java/org/springframework/integration/flow/config/xml/Foo.java b/src/test/java/org/springframework/integration/flow/config/xml/Foo.java index 6f61f7f..424a65e 100644 --- a/src/test/java/org/springframework/integration/flow/config/xml/Foo.java +++ b/src/test/java/org/springframework/integration/flow/config/xml/Foo.java @@ -1,8 +1,7 @@ package org.springframework.integration.flow.config.xml; -import org.springframework.beans.factory.annotation.Autowired; + public class Foo { - @Autowired Bar bar; } diff --git a/src/test/java/org/springframework/integration/flow/config/xml/FooFactory.java b/src/test/java/org/springframework/integration/flow/config/xml/FooFactory.java new file mode 100644 index 0000000..66d31cb --- /dev/null +++ b/src/test/java/org/springframework/integration/flow/config/xml/FooFactory.java @@ -0,0 +1,29 @@ +package org.springframework.integration.flow.config.xml; + +import org.springframework.beans.factory.FactoryBean; +import org.springframework.beans.factory.annotation.Autowired; +public class FooFactory implements FactoryBean{ + + @Autowired + Bar bar; + @Override + public Foo getObject() throws Exception { + // TODO Auto-generated method stub + Foo foo = new Foo(); + foo.bar = bar; + return foo; + } + + @Override + public Class getObjectType() { + // TODO Auto-generated method stub + return Foo.class; + } + + @Override + public boolean isSingleton() { + // TODO Auto-generated method stub + return true; + } + +} diff --git a/src/test/resources/META-INF/spring/integration/flows/transactional-flow/flow-context.xml b/src/test/resources/META-INF/spring/integration/flows/transactional-flow/flow-context.xml index 8264bc3..3e57eec 100644 --- a/src/test/resources/META-INF/spring/integration/flows/transactional-flow/flow-context.xml +++ b/src/test/resources/META-INF/spring/integration/flows/transactional-flow/flow-context.xml @@ -1,14 +1,15 @@ diff --git a/src/test/resources/autowired-referenced-beans.xml b/src/test/resources/autowired-referenced-beans.xml index 59db78f..c34e251 100644 --- a/src/test/resources/autowired-referenced-beans.xml +++ b/src/test/resources/autowired-referenced-beans.xml @@ -3,6 +3,6 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> - +