diff --git a/spring-bootstrap-cli/samples/integration.groovy b/spring-bootstrap-cli/samples/integration.groovy index 5d5ce23039..ae746b0415 100644 --- a/spring-bootstrap-cli/samples/integration.groovy +++ b/spring-bootstrap-cli/samples/integration.groovy @@ -1,15 +1,17 @@ package org.test @Component +@EnableIntegrationPatterns class SpringIntegrationExample implements CommandLineRunner { - def builder = new IntegrationBuilder() - def flow = builder.messageFlow { - transform {"Hello, $it!"} + @Bean + MessageFlow flow(ApplicationContext context) { + def builder = new IntegrationBuilder(context) + builder.messageFlow { transform {"Hello, $it!"} } } - @Override - public void run(String... args) { - print flow.sendAndReceive("World") + @Override + void run(String... args) { + print flow().sendAndReceive("World") } } diff --git a/spring-bootstrap-cli/samples/worker.groovy b/spring-bootstrap-cli/samples/worker.groovy new file mode 100644 index 0000000000..c96696f593 --- /dev/null +++ b/spring-bootstrap-cli/samples/worker.groovy @@ -0,0 +1,20 @@ +package org.test + +@Grab("org.springframework.bootstrap:spring-bootstrap-service:0.0.1-SNAPSHOT") +@Grab("org.springframework.integration:spring-integration-dsl-groovy-amqp:1.0.0.M1") + +@Component +@EnableIntegrationPatterns +class SpringIntegrationExample implements CommandLineRunner { + + @Bean + MessageFlow flow(ApplicationContext context) { + def builder = new IntegrationBuilder(context) + builder.messageFlow { transform {"Hello, $it!"} } + } + + @Override + void run(String... args) { + print flow().sendAndReceive("World") + } +} diff --git a/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/compiler/autoconfigure/SpringBootstrapCompilerAutoConfiguration.java b/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/compiler/autoconfigure/SpringBootstrapCompilerAutoConfiguration.java index 6243b11495..880bbb01b6 100644 --- a/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/compiler/autoconfigure/SpringBootstrapCompilerAutoConfiguration.java +++ b/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/compiler/autoconfigure/SpringBootstrapCompilerAutoConfiguration.java @@ -72,6 +72,8 @@ public class SpringBootstrapCompilerAutoConfiguration extends CompilerAutoConfig "org.springframework.context.annotation.Scope", "org.springframework.context.annotation.Configuration", "org.springframework.context.annotation.Bean", + "org.springframework.context.ApplicationContext", + "org.springframework.context.MessageSource", "org.springframework.core.io.ResourceLoader", "org.springframework.bootstrap.CommandLineRunner", "org.springframework.bootstrap.context.annotation.EnableAutoConfiguration"); diff --git a/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/compiler/autoconfigure/SpringIntegrationCompilerAutoConfiguration.java b/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/compiler/autoconfigure/SpringIntegrationCompilerAutoConfiguration.java index a07fe76256..9940c5d13b 100644 --- a/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/compiler/autoconfigure/SpringIntegrationCompilerAutoConfiguration.java +++ b/spring-bootstrap-cli/src/main/java/org/springframework/bootstrap/cli/compiler/autoconfigure/SpringIntegrationCompilerAutoConfiguration.java @@ -16,6 +16,12 @@ package org.springframework.bootstrap.cli.compiler.autoconfigure; +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + import org.codehaus.groovy.ast.ClassNode; import org.codehaus.groovy.control.customizers.ImportCustomizer; import org.springframework.bootstrap.cli.compiler.AstUtils; @@ -33,8 +39,8 @@ public class SpringIntegrationCompilerAutoConfiguration extends CompilerAutoConf public boolean matches(ClassNode classNode) { // Slightly weird detection algorithm because there is no @Enable annotation for // Integration - return AstUtils.hasLeastOneAnnotation(classNode, "MessageEndpoint") - || classNode.getName().contains("SpringIntegration"); + return AstUtils.hasLeastOneAnnotation(classNode, "MessageEndpoint", + "EnableIntegrationPatterns"); } @Override @@ -59,6 +65,15 @@ public class SpringIntegrationCompilerAutoConfiguration extends CompilerAutoConf "org.springframework.integration.annotation.Headers", "org.springframework.integration.annotation.Payload", "org.springframework.integration.annotation.Payloads", + EnableIntegrationPatterns.class.getCanonicalName(), + "org.springframework.integration.dsl.groovy.MessageFlow", "org.springframework.integration.dsl.groovy.builder.IntegrationBuilder"); } + + @Target(ElementType.TYPE) + @Documented + @Retention(RetentionPolicy.RUNTIME) + public static @interface EnableIntegrationPatterns { + + } } diff --git a/spring-bootstrap/src/main/java/org/springframework/bootstrap/BeanDefinitionLoader.java b/spring-bootstrap/src/main/java/org/springframework/bootstrap/BeanDefinitionLoader.java index 39f4d43c78..e90e5e00d7 100644 --- a/spring-bootstrap/src/main/java/org/springframework/bootstrap/BeanDefinitionLoader.java +++ b/spring-bootstrap/src/main/java/org/springframework/bootstrap/BeanDefinitionLoader.java @@ -163,7 +163,7 @@ class BeanDefinitionLoader { } // Nested anonymous classes are not eligible for registration, nor are groovy // closures - if (type.isAnonymousClass() || type.getName().contains("$_closure") + if (type.isAnonymousClass() || type.getName().matches(".*\\$_.*closure.*") || type.getConstructors() == null || type.getConstructors().length == 0) { return false; }